[英]How to create a custom function which i can turn it off on a click?
I am running a bit of code once the page load so in the footer i have got: 页面加载后,我正在运行一些代码,因此在页脚中我得到了:
$(function(){
//code to run on page load
});
But then i need to stop that code to run on a 但是然后我需要停止该代码才能在
.click()
I was thinking of having a custom function which runs on page load and then be able to disabale that function on a click. 我当时想拥有一个自定义功能,该功能可以在页面加载时运行,然后在单击时就可以取消该功能。
How to create a custom function which i can turn it off on a click? 如何创建自定义功能,我可以在单击时将其关闭?
A simple way would be to add a flag/preference variable to your page, which dictates which logic can be executed and when. 一种简单的方法是在页面中添加标志/首选项变量,该变量指示可以执行哪些逻辑以及何时执行。
Whenever code is then executed, just check the preference, ie 每当执行代码时,只需检查首选项即可,即
function myfunction () {
....
if (code_may_run) {
....
code_may_run = false;
}
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.