Regarding the image carousel, setting up automatic playback issues:
If you use native JS code, I currently know two methods, the first one:
function next(){ 这里是代码,比如index++; } var timer=setInterval(next, 2000);
The second type (where oBtnNext refers to a button obtained):
oBtnNext.onclick=function(){ 这里是代码,比如index++; } var timer=setInterval(oBtnNext.onclick,2000);
Here comes the point. The question is, if jQuery($("#next") is equivalent to oBtnNext above)
$("#next").click(function(){ 这里是代码,比如index++; }
Why write
var timer=setInterval($("#next").click,2000)
or
var timer=setInterval($("#next").click(),2000)
is not allowed, but
var timer=setInterval(function () { $("#next").click() },2000);
But it works.
You still don’t understand the usage of setInterval
setInterval(code, millisec[,"lang"])
The code is the function to be called or the code string to be executed.
When using code strings, add "" to turn the method into a string..
(See w3school for details)
This is easy to use because oBtnNext.onclick is a function
or
It doesn’t work, because these two are neither functions nor code strings. You can try writing