我的 Jquery one()
函数在第二次单击而不是第一次单击后终止。这是我的 HTML
<div class="box">
<div class="call" data-tai="5">CLICK</div>
</div>
这是我的 Jquery
$('body div').one('click', '.call', function() {
var mother = $(this).parent();
if(mother.css('position') === 'static')
mother.css('position', 'relative');
var tai = $(this).data('tai');
$.ajax({
method: 'GET',
url: '/bootstrap/call.php',
data: 'tai='+tai,
dataType: 'html',
success: function(ret) {
mother.append(ret);
},
});
return false;
});
有趣的是,如果我不使用return false;
,它会在第一次点击后消失。然而,冒泡
发生了,它在box
元素内附加了2个html标签而不是1个。感谢您的帮助
最佳答案
$('body div')
将选择这两个 div 并将单击处理程序附加到它们。当您单击嵌套的 div 时,两次单击都会被触发。使用特定的选择器可以避免这种情况。
$('.call')
也许可以实现这一目标。
关于javascript - Jquery one() 函数在单击时触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680182/