我有一个简单的超链接HTML页面。该链接完美工作并执行jQuery函数。我会警告说“现在”。jQuery和防止函数执行两次超链接双击
问题是,当用户双击链接时,它将执行两次jQuery代码,并将“现在”警报两次。当我下次单击链接一次时,它会执行jQuery代码两次甚至更多次,我会得到几个“Now”警报。
我应该如何修改我的代码以防止多次执行jQuery代码?
下面是HTML代码:
<a href="#" class="editing" data-match="1" data-place="1" data-selected="20" data-checking="area">Use</a>
这里是我的jQuery代码:
jQuery(document).on('click', '.editing', function(e) {
e.preventDefault();
var $this = $(this),
match = $this.data('match'),
place = $this.data('place'),
selected = $this.data('selected'),
checking = $this.data('checking');
jQuery.post("myownpage.php", {
match: match,
place: place,
selected: selected,
checking: checking
}).done(function(data) {
alert('Now');
$('html').css({ 'overflow': 'auto', 'height': 'auto' });
$this.parent().parent().parent().parent().parent().parent().css('display', 'none');
});
});
你可以使用'.one',然后重新绑定您的点击后完成 – Pete
后,你希望链接可以点击每个每个页面加载只有一次? –
@AlaaMh是的,我想是的。 – xms