问题
$(function() {
setInterval( "clickRight()", 5000 );
});
$('.slide_right').click(function clickRight(){
etc...
I basically want my slideshow to move to the next slide as if the user clicked the right button. This example is not working for me.
回答1:
setInterval( "clickRight()", 5000 );
function clickRight()
{
$('.slide_right').trigger('click');
};
回答2:
$('.slide_right').trigger('click');
or
$('.slide_right').click();
回答3:
You can trigger an event
$("element").trigger("event");
Bind the event to an element:
$("element").bind("event");
It does accept normal events like click, ... and also custom events.
回答4:
You can use trigger to force your event:
function clickRight(){
$('.slide_right').trigger('click');
}
$(function() {
setInterval( "clickRight()", 5000 );
});
回答5:
You can give a name to the click function and do a setInterval like this...
$("#Id").click(function _clickFunction(){
something();
};
interval=setInterval( function{
_clickFunction();
},5000);
来源:https://stackoverflow.com/questions/4819198/executing-a-click-function-without-the-user-clicking