一旦执行jquery unbind函数事件
大家好, 请帮助我解决这个问题:假设我们从锚点调用相同的javascript函数,但参数不同一旦执行jquery unbind函数事件,jquery,function,bind,unbind,die,Jquery,Function,Bind,Unbind,Die,大家好, 请帮助我解决这个问题:假设我们从锚点调用相同的javascript函数,但参数不同 <a id="edit1" onclick="foo(1)"></a> <a id="edit2" onclick="foo(2)"></a> function foo(id) { // let's say the code here hide the clicked anchor and show a new anchor with cancel-e
<a id="edit1" onclick="foo(1)"></a>
<a id="edit2" onclick="foo(2)"></a>
function foo(id)
{
// let's say the code here hide the clicked anchor and show a new anchor with cancel-edit id
}
函数foo(id)
{
//假设这里的代码隐藏单击的锚并显示一个带有cancel edit id的新锚
}
情景:
- 我点击了第一个锚点-第一个锚点替换为新锚点:
- 如何禁用该功能,以便在单击第二个锚点时,该功能不起任何作用。
- 现在假设我点击了id为cancel edit的锚点,它将撤回id为edit1的锚点,并重新激活foo函数,因此当我重新点击第二个锚点时,它将再次执行foo函数李>
提前感谢。如果要在单击一个元素后对所有元素禁用它,您只需设置一个标志:
var enabled = true;
function foo(id) {
if( enabled ) {
// run your code
enabled = false;
}
}
它将继续运行,但第一次单击后,if
语句中的代码将不会运行
function stop() {
// replace the original anchor
enabled = true; // enable the "foo" handler
}
单击带有
stop()
的新锚点时,您可以将其替换为原始锚点,并将enabled
设置为true
,以便foo()
再次工作。感谢您的快速回复!对不起,我没有很好地解释我想做什么。这是一个场景:-我点击了第一个锚点-第一个锚点被一个新锚点替换:-现在当我点击第二个锚点时,它什么也不做-但是当我点击调用javascript停止函数的新锚点时,它确实重新激活了foo函数-当我重新点击第二个锚点时,它会起作用的。对不起,我英语不好,我尽力了@v1r00z:您需要编辑您的问题,并添加更多代码和详细信息。@v1r00z:我更新了我的答案。只需将stop()
函数设置为enabled=true
,这样foo
就可以再次工作。