Javascript jQuery停止其他函数';什么是死刑?
我想在我的代码中停止另一个函数的执行,我的JS代码如下所示:Javascript jQuery停止其他函数';什么是死刑?,javascript,jquery,Javascript,Jquery,我想在我的代码中停止另一个函数的执行,我的JS代码如下所示: <script> $(document).ready(function() { <?php if ($saveMethod) : ?> $("#running").html('<b>Save</b>'); <?php else : ?> $("#running").html('<b>Skip
<script>
$(document).ready(function() {
<?php if ($saveMethod) : ?>
$("#running").html('<b>Save</b>');
<?php else : ?>
$("#running").html('<b>Skip</b>');
<?php endif; ?>
$("#running").click(function() {
// tried to stop customRedirect();
return false;
});
<?php if ($redirectURL != '') : ?>
customRedirect (10, "timer", "<?= $redirectURL ?>");
<?php endif; ?>
});
</script>
如果用户单击
#running
我想停止执行customRedirect
,我不知道您的customRedirect
,也许您可以在该函数中实现它,但诀窍是将setTimeout
赋值给一个变量,这样我们就可以在不希望它再次发生时清除它:
let delayedRedirect = setTimeout( function(){
window.location = '<?= $redirectURL ?>';
// or your customRedirect() if you have anything fancy
}, 10 *1000);
$("#running").html('<b><?=$saveMethod? "Save" : "Skip" ?></b>');
$("#running").click(function() {
clearTimeout(delayedRedirect);
});
let delayedRedirect=setTimeout(函数(){
window.location='';
//或者你的customRedirect()如果你有什么想法
}, 10 *1000);
$(“#运行”).html(“”);
$(“#正在运行”)。单击(函数(){
clearTimeout(delayedRedirect);
});
PHP标签在哪里?我不明白你想要什么。@MiquelAl.Vicens如果用户单击$(“#running”),那么我想停止customRedirect()执行。像这样混合html
jquery
PHP
很奇怪!你不需要这个。浏览器中只有一个线程运行JS,不能同时运行两个单独的函数,因此不需要停止另一个函数。
let delayedRedirect = setTimeout( function(){
window.location = '<?= $redirectURL ?>';
// or your customRedirect() if you have anything fancy
}, 10 *1000);
$("#running").html('<b><?=$saveMethod? "Save" : "Skip" ?></b>');
$("#running").click(function() {
clearTimeout(delayedRedirect);
});