我有一个带有css类confirmDelete的asp net gridview linkbutton,我已经使用像这样的jquery附加了一个click事件
$('.confirmDelete').click(function (e) {
return confirm('Are you sure you want to delete!!');
});
但它不起作用;它显示了确认对话框,无论我们点击什么,它都会停止按钮处理程序。
另一方面,像这样的内联点击事件
<asp:LinkButton runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this?');" CssClass="btn btn-danger confirmDelete"></asp:LinkButton>
提前致谢
答案 0 :(得分:0)
我会试试这个:
$('.confirmDelete').click(function (e) {
var confirm = window.confirm('Are you sure you want to delete!!');
if (confirm) {
// do all the things
}
});
答案 1 :(得分:0)
没有必要为此创建一个jquery函数,只需这样写:
<asp:LinkButton runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this?');" CssClass="btn btn-danger" ID="delete" OnClick="delete_Click"></asp:LinkButton>
这将是这样的: 当您单击链接按钮时,如果按OK则会出现确认对话框,然后服务器事件将触发其他服务器事件将不会触发
答案 2 :(得分:0)
您需要在$(document).ready()。
中添加click事件$(document).ready(function () {
$('.confirmDelete').click(function (e) {
return confirm('Are you sure you want to delete!!');
});
);