问题是,如何通过一次调用关闭所有事件,例如,如果我有其他事件,如'mouseleave,mouseenter,keyup,keydown ......'。
我在这里做的是每次显示对话框时我关闭(off
)事件,这个'off
'适用于click
,但我想要我通过一次调用来关闭所有事件的代码:$('.dialog').off('**');
但它不起作用。如果我不使用off,我会多次调用click(多个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>
答案 0 :(得分:2)
答案 1 :(得分:0)