gpt4 book ai didi

php - 如何一次调用 'off' 所有事件

转载 作者:行者123 更新时间:2023-12-02 18:32:58 25 4
gpt4 key购买 nike

问题很简单,如何通过一次调用关闭所有事件,例如,如果我有另一个事件,如“mouseleave、mouseenter、keyup、keydown ...”。

我在这里所做的是,每次显示对话框时我都会关闭(off)事件,这个“off”与配合得很好单击,但我想要一个代码通过一次调用关闭所有事件,我尝试过: $('.dialog').off('**'); 但它没有'有效。如果我不使用 off,我会收到多次点击调用(多个 hello worlds)。

我有这样的代码:

myform.php

<script type="text/javascript">
$(document).ready( function () {
$('.dialog').off('click');
$('.dialog').on('click', '.mybutton', function() {
alert('hello world');
});
});
</script>
<input type="button" class="mybutton" value="click me!"/>

html:

<html>
<head>
<script type="text/javascript">
$(document).ready( function () {
function openDialog()
{
$.post( '/myform.php', null, function (data) {
$('.dialog').html( data );
$('.dialog').show();
});
}

function closeDialog()
{
$('.dialog').hide();
$('.dialog').html('');
}
});
</script>
</head>
<body>
<div class="dialog" style="display:none">

</div>
<input type="button" onclick="openDialog();" value="show dialog!" />
<input type="button" onclick="closeDialog();" value="close dialog!" />
</body>
</html>

最佳答案

您不能传递任何参数,它会解除所有参数的绑定(bind)。

$("element").off();

jsFiddle .

关于php - 如何一次调用 'off' 所有事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com