Tal*_*lha 5 jquery timedelay delay
我有一个按钮,通过点击另一个按钮触发.我想延迟点击第二个按钮两秒钟.我使用.delay()但它没有用.
jq(function() {
jq('a.box').click(function() {
jq(this).closest('.button').find('.add_this').delay(2000).click();
})
});
Run Code Online (Sandbox Code Playgroud)
或者使用setTimeout;
jq(function() {
jq('a.box').click(function() {
setTimeout(function(){
jq(this).closest('.button').find('.add_this').click();
},800);
});
});
Run Code Online (Sandbox Code Playgroud)
但没有奏效.
dak*_*ait 14
来自文档http://api.jquery.com/delay/
.delay()方法最适合延迟排队的jQuery效果.因为它是有限的 - 例如,它没有提供取消延迟的方法 - .delay()不能替代JavaScript的本机setTimeout函数,这可能更适合某些用例.
你可以用来setTimeout在延迟后绑定点击处理程序
setTimeout(function(){
jq('a.box').closest('.button').find('.add_this').click();
},2000);
Run Code Online (Sandbox Code Playgroud)
编辑
jq(function() {
jq('a.kklike-box').click(function() {
$this = $(this);
setTimeout(function(){
$this.closest('.deal_buttons').find('.add_this').click();
},800);
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42274 次 |
| 最近记录: |