<asp:LinkButton ID="btn_Delete" runat="server" OnClick="btn_Delete_Click" OnClientClick="ConfirmDelete();" Text="Delete" />
确认删除如下所示:
function ConfirmDelete() { var answer = confirm("Are you SURE you want to delete this item?"); if (!answer) { return false; } };
我曾假设这会阻止页面在用户点击取消时回发,但它似乎仍然会回发.有什么方法可以防止使用确认回发吗?
OnClientClick="return ConfirmDelete();"
顺便说一句,你不需要函数中的所有逻辑,只需返回确认调用的结果:
function ConfirmDelete() { return confirm("Are you SURE you want to delete this item?"); };