我有一个表格,其中填充了数据库中的数据,其中每一行都有一个单元格,其中有一个 anchor 元素。这个 anchor 将指向相同的页面,但带有一个查询字符串,告诉 php 哪一行包含它应该删除的数据。
我需要在用户单击 anchor 时打开一个 jQuery 对话框,要求他在加载 url 之前确认他的意图。 “取消”按钮应该关闭对话框并且什么都不做。然后“确定”按钮应该让 url 打开。
非常感谢任何帮助。
//使用“我尝试过的”进行编辑。这是我第一次弄乱 jQuery,学习的时间不多了... =(
jQuery(document).ready(function(){
var $dialog = jQuery('<div class='msg_dialog'></div>')
.html('Are you sure you want to do this?')
.dialog({
autoOpen: false,
title: 'Confirm action',
buttons: [{
text: "Cancel",
click: function(){
jQuery(this).dialog("close");
}
}] // didn't even try the OK button since I couldn't even get the dialog opened
});
jQuery('#confirm_del').click(function(){
$dialog.dialog('open');
return false;
});
});
最佳答案
$("a").on("click", function(e) {
var link = this;
e.preventDefault();
$("<div>Are you sure you want to continue?</div>").dialog({
buttons: {
"Ok": function() {
window.location = link.href;
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
});
示例: http://jsfiddle.net/uRGJD/
(重定向到 Google 在 JSFiddle 上不起作用,但应该在普通页面上起作用)
关于php - 打开链接前的 jQuery 对话框确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532738/