如何在特定按钮上设置Onbeforeunload函数? 例如,我有3个按钮。允许在ASP.NET Framework上的特定按钮上使用Javascript Onbeforeunload函数
<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不起作用。这个怎么做?有任何想法吗?我只想触发指定按钮上的功能。帮我。
它是如何工作的? – artm 2014-10-08 05:21:42
我只想在“返回”按钮上应用该功能。不在两个按钮上(btnSumbit,btnSaveToDraft)。我使用了上面的语法,但它不起作用。或者我应该使用更好的功能? – Jarich 2014-10-08 05:26:11