我有一个在ready上触发的函数Start()。当我单击.ExampleClick时,我想停止运行函数Start()。这是我的例子..。
$(document).ready(function(){
$(function Start(){
// Do Stuff on Ready
});
$(document).on("click",".ExampleClick",function() {
// When this is fired, function Start() should stop running
});
});实现我想要做的事情的最好方法是什么?
发布于 2012-03-21 01:59:42
听起来你有一个函数想要重复运行,然后当你点击时停止它:
doStuff = function() {
// stuff to do regularly
}
$(document).ready(function(){
// run doStuff every 2 seconds
var jobId = window.setInterval(doStuff, 2000);
// store the job id in a jquery data object
$('body').data("doStuffJobId", jobId);
// set up click hander for css class Example Click
$(".ExampleClick").click(function() {
// get the job id
var jobId = $('body').data("doStuffJobId");
window.clearInterval(jobId);
});
});https://stackoverflow.com/questions/9792235
复制相似问题