gpt4 book ai didi

javascript - 在文档上使用 jquery 添加点击事件跟踪器时,链接上的点击事件不起作用

转载 作者:行者123 更新时间:2023-12-03 08:50:36 25 4
gpt4 key购买 nike

我有一个文件列表,并且可以选择删除该文件。因此,单击删除后,它会要求确认。单击确认后,文件将被删除。请检查这个 jsfiddle

https://jsfiddle.net/d6ds7qL2/1/

当我添加 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;
});

https://jsfiddle.net/d6ds7qL2/2/

但现在的问题是单击“确认”文本时,它不会跳转到 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/

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