我可以停止回发使用JavaScript的确认? [英] Can I stop a post back by using javascripts confirm?
本文介绍了我可以停止回发使用JavaScript的确认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有页面上的asp.net按钮aspx页:
I have an aspx page with a asp.net button on the page:
<asp:LinkButton ID="btn_Delete" runat="server" OnClick="btn_Delete_Click" OnClientClick="ConfirmDelete();" Text="Delete" />
确认删除这个样子的:
Confirm delete looks like this:
function ConfirmDelete() {
var answer = confirm("Are you SURE you want to delete this item?");
if (!answer) {
return false;
}
};
我曾以为,这将prevent页从如果用户点击取消回发,但它仍然似乎回发。有没有一些方法,我可以确认使用prevent回发?
I had assumed that this would prevent the page from posting back if the user clicked cancel, but it still appears to be posting back. Is there some way I can prevent postback using confirm?
推荐答案
您必须从事件处理函数返回值:
You have to return the value from the function in the event handler:
OnClientClick="return ConfirmDelete();"
顺便说一句,你并不需要所有的逻辑函数中,只返回从确认结果
电话:
function ConfirmDelete() {
return confirm("Are you SURE you want to delete this item?");
};
这篇关于我可以停止回发使用JavaScript的确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文