[英]jquery click not working after confirm
I´ve a strange problem. 我有一个奇怪的问题。 I am providing a link which sends an ajax request to delete a user.
我正在提供一个链接,该链接发送ajax请求以删除用户。 If the User clicks a link for the first time and confirms the confirm box the ajax function is triggered.
如果用户第一次单击链接并确认确认框,则触发ajax功能。 but if the user after that again clicks a link with class delUser, nothing happens.
但是,如果此后用户再次单击delUser类的链接,则不会发生任何事情。 No confirm Box nothing, It seems the click function is ignored than.
没有确认框什么也没有,看来比点击功能被忽略了。 I found out if I cut the part with the confirmbox everything works fine.
我发现如果我用Confirmbox切割零件,一切正常。
Whats wrong with this confirm? 这个确认有什么问题吗?
jQuery(".delUser").click(function(){
// open confirm Window
confirm = window.confirm("Nutzer wirklich löschen?");
User = $(this).attr("data-link");
if(confirm == true){
jQuery.ajax({
type: "POST",
url: "/Admin/DelUser.php",
data: { where: User },
success: function(retData){
jQuery.noticeAdd({text: "" + retData + "",
stay: false,
type: 'error'
});
}
});
$(this).closest('tr').remove();
} else {
talk("Nutzer wurde nicht gelöscht");
}
});
Kind regards, 亲切的问候,
Tony 托尼
Because you are overwriting confirm
. 因为您正在覆盖
confirm
。
This line: 这行:
confirm = window.confirm("Nutzer wirklich löschen?");
is equal to 等于
window.confirm = window.confirm("Nutzer wirklich löschen?");
One of the reasons why using globals is a very bad idea . 使用全局变量的原因之一是一个非常糟糕的主意 。 When you are declaring a variable , please always use
var
, so it will not be global: 在声明变量时 ,请始终使用
var
,因此它不会是全局的:
var confirm = window.confirm("Nutzer wirklich löschen?");
The same would apply to User
. 同样适用于
User
。 You should declare it like: 您应该这样声明:
var User = $(this).attr("data-link");
Try this: 尝试这个:
jQuery(".delUser").click(function(){
User = $(this).attr("data-link");
if(window.confirm("Nutzer wirklich löschen?")){
jQuery.ajax({
type: "POST",
url: "/Admin/DelUser.php",
data: { where: User },
success: function(retData){
jQuery.noticeAdd({text: "" + retData + "",
stay: false,
type: 'error'
});
}
});
$(this).closest('tr').remove();
} else {
talk("Nutzer wurde nicht gelöscht");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.