我有一个文件列表,并且可以选择删除该文件。因此,单击删除后,它会要求确认。单击确认后,文件将被删除。 请检查这个 jsfiddle
当我添加 html 点击处理程序以便将确认文本更改为原始删除文本时,
$('html').click(function(event){ if($('.confirmDelete').is(':visible')){ $('.confirmDelete').hide(); $('.deleteLink').show(); return false; } }); $('.confirmDelete').hide(); $('.deleteLink').click(function (event) { $(this).hide(); $('.confirmDelete').filter(':visible').each(function () { $(this).hide(); $(this).prev('.deleteLink').show(); }); $(this).next('.confirmDelete').show(); event.stopPropagation(); return false; });
但现在的问题是单击“确认”文本时,它不会跳转到 href,而是隐藏确认文本并显示删除文本。
最佳答案
尝试用 document
代替 html
。
$(document).not(".confirmDelete").click(function(event){
if($('.confirmDelete').is(':visible')){
$('.confirmDelete').hide();
$('.deleteLink').show();
return false;
}
});
$('.confirmDelete').hide();
$('.deleteLink').click(function (event) {
$(this).hide();
$('.confirmDelete').filter(':visible').each(function () {
$(this).hide();
$(this).prev('.deleteLink').show();
});
$(this).next('.confirmDelete').show();
event.stopPropagation();
return false;
});
fiddle :https://jsfiddle.net/945j4g0x/
关于javascript - 在文档上使用 jquery 添加点击事件跟踪器时,链接上的点击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693169/