【发布时间】:2014-12-02 16:24:30
【问题描述】:
如何在特定按钮上设置 Onbeforeunload 功能? 例如,我有 3 个按钮。
<div>
<asp:Button ID="btnBack" runat="server" Text="Back" CssClass="po-font" Height="30px"/>
<asp:Button ID="btnSumbit" runat="server" Text="Submit" CssClass="po-font" Height="30px"/>
<asp:Button ID="btnSaveToDraft" runat="server" Text="Save To Draft" CssClass="po-font" Height="30px"/>
</div>
在 javascript 上,我做了类似的事情:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Are you sure you want to leave this page? Any unsaved progress will be lost";
}
</script>
该功能将正常工作,但我想在特定按钮中指定该功能,可能在“返回”按钮上。我做了类似的事情。
<script type="text/javascript">
function confirmExit()
{
return "Are you sure you want to leave this page? Any unsaved progress will be lost";
}
$('#btnBack').live('click', function () {
window.onbeforeunload = confirmExit;
});
</script>
但 ID 不起作用。这个怎么做?有任何想法吗?我只想触发指定按钮上的功能。帮帮我。
【问题讨论】:
-
怎么不工作?
-
我只想在“返回”按钮上应用该功能。不在两个按钮上(btnSumbit,btnSaveToDraft)。我使用了上面的语法,但它不起作用。还是应该使用更好的功能?
标签: javascript c# jquery c#-4.0