admin管理员组文章数量:1025516
My program has two buttons. One is for execute other program by using jquery load function. Whenever I click execute button, it runs some other program abc.php
using load function for n times, with some time gap like k mins. These n and k will be filled with html inputs. Using jquery, will retrieve these and passing to that program file in url.
To call this function setTimeout
was used.
Second one is for cancel execution.
Now my doubt is, suppose I want to stop that execution with cancel button. Is there any way to stop it ?
My program has two buttons. One is for execute other program by using jquery load function. Whenever I click execute button, it runs some other program abc.php
using load function for n times, with some time gap like k mins. These n and k will be filled with html inputs. Using jquery, will retrieve these and passing to that program file in url.
To call this function setTimeout
was used.
Second one is for cancel execution.
Now my doubt is, suppose I want to stop that execution with cancel button. Is there any way to stop it ?
Share Improve this question edited Dec 13, 2013 at 10:42 Praveen 56.6k35 gold badges136 silver badges166 bronze badges asked Dec 13, 2013 at 10:35 user2881803user2881803 31 silver badge3 bronze badges 4- 1 You should really give a code example of your JavaScript, but most likely you're talking about how to do this – Philipp Gayret Commented Dec 13, 2013 at 10:37
- Check this – skos Commented Dec 13, 2013 at 10:38
- Are you connecting to the PHP file ones at the time (re connect after other connection finishes) or all at the same time? – HMR Commented Dec 13, 2013 at 10:38
- w3schools./jsref/met_win_cleartimeout.asp OR w3schools./jsref/… – user2801382 Commented Dec 13, 2013 at 10:40
2 Answers
Reset to default 4I would do this using boolean
variable.
For example: Consider a method, perform logging.
fun () {
console.log("prints");
}
I would change it has
fun (isExecute) {
if (isExecute) {
console.log("prints");
}
}
Run fun (true);
cancel fun (false);
Updates:
It seems you use setTimeout()
, then it is too easy without above approach.
Run var inter = setTimeout(fun);
cancel clearTimeout(inter);
FYI: The reason for assigning to a variable inter
is then only you can clear this time interval.
set time for function:
timer = setTimeout(function(){$('#submenu').hide();},5000);
stop a function
clearTimeout(timer);
My program has two buttons. One is for execute other program by using jquery load function. Whenever I click execute button, it runs some other program abc.php
using load function for n times, with some time gap like k mins. These n and k will be filled with html inputs. Using jquery, will retrieve these and passing to that program file in url.
To call this function setTimeout
was used.
Second one is for cancel execution.
Now my doubt is, suppose I want to stop that execution with cancel button. Is there any way to stop it ?
My program has two buttons. One is for execute other program by using jquery load function. Whenever I click execute button, it runs some other program abc.php
using load function for n times, with some time gap like k mins. These n and k will be filled with html inputs. Using jquery, will retrieve these and passing to that program file in url.
To call this function setTimeout
was used.
Second one is for cancel execution.
Now my doubt is, suppose I want to stop that execution with cancel button. Is there any way to stop it ?
Share Improve this question edited Dec 13, 2013 at 10:42 Praveen 56.6k35 gold badges136 silver badges166 bronze badges asked Dec 13, 2013 at 10:35 user2881803user2881803 31 silver badge3 bronze badges 4- 1 You should really give a code example of your JavaScript, but most likely you're talking about how to do this – Philipp Gayret Commented Dec 13, 2013 at 10:37
- Check this – skos Commented Dec 13, 2013 at 10:38
- Are you connecting to the PHP file ones at the time (re connect after other connection finishes) or all at the same time? – HMR Commented Dec 13, 2013 at 10:38
- w3schools./jsref/met_win_cleartimeout.asp OR w3schools./jsref/… – user2801382 Commented Dec 13, 2013 at 10:40
2 Answers
Reset to default 4I would do this using boolean
variable.
For example: Consider a method, perform logging.
fun () {
console.log("prints");
}
I would change it has
fun (isExecute) {
if (isExecute) {
console.log("prints");
}
}
Run fun (true);
cancel fun (false);
Updates:
It seems you use setTimeout()
, then it is too easy without above approach.
Run var inter = setTimeout(fun);
cancel clearTimeout(inter);
FYI: The reason for assigning to a variable inter
is then only you can clear this time interval.
set time for function:
timer = setTimeout(function(){$('#submenu').hide();},5000);
stop a function
clearTimeout(timer);
本文标签: jqueryhow to stop Javascript function executionStack Overflow
版权声明:本文标题:jquery - how to stop Javascript function execution? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626629a2159902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论