当用户点击按钮时,我想将Are you sure you want to delete this comment?
作为弹出提醒。那怎么样?
$('button').on('click', function(){
// show a alert to the user contains "Are you sure you want to delete this comment?"
if ( /* he pressed "yes" */ ) {
var id = $(this).attr('id');
deleteComment(id);
} else {
// nothing happens
}
});
答案 0 :(得分:3)
$('button').on('click', function(){
if (confirm("Do you really want to delete?")) {
var id = $(this).attr('id');
deleteComment(id);
} else {
return false;
}
});
答案 1 :(得分:2)
超级简单!只需将确认对话框分配给变量
即可"select top 10 CustomerID from CustList"
由于js是同步的,它将逐行运行代码!确认对话框将在运行后阻止任何内容。
答案 2 :(得分:1)
$('button').on('click', function(){
answer = confirm("Are you sure?")
if (answer == true) {
var id = $(this).attr('id');
deleteComment(id);
} else {
// nothing happens
}
});
答案 3 :(得分:1)
这个概念与上面三个答案相同。它将改变您实现逻辑的方式。
$('button').on('click', function(){
if (confirm("your dialog here") === true ) {
var id = $(this).attr('id');
deleteComment(id);
} else {
// nothing happens
}
});