executing a click function without the user clicking?

耗尽温柔 提交于 2021-02-06 13:58:05

问题


$(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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!