我有一个通过jQuery绑定到链接的ajax调用,我希望它被一个确认对话框截获。但是,无论选择哪个选项,ajax调用都会触发(即使用户只是关闭了对话框)。
有没有办法让confirm像在同步上下文中那样工作?
HTML:
<a href="#" class="removeItem delete">remove</a>
jQuery:
$('.delete').click(function () {
confirm('Are you sure you want to delete this?');
});
$('.removeItem').click(function (event) {
event.preventDefault();
$.ajax({
url: 'myUrl',
type: "POST",
data: {
// data stuff here
},
success: function () {
// does some stuff here...
}
});
});
发布于 2011-06-17 18:11:12
$('.removeItem').click(function (event) {
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: 'myUrl',
type: "POST",
data: {
// data stuff here
},
success: function () {
// does some stuff here...
}
});
}
});
https://stackoverflow.com/questions/6384251
复制相似问题