gpt4 book ai didi

javascript - 允许 ASP.NET Framework 上的特定按钮上的 Javascript Onbeforeunload 函数

转载 作者:行者123 更新时间:2023-11-28 07:54:46 24 4
gpt4 key购买 nike

如何在特定按钮上设置 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 不起作用。这个怎么做?有任何想法吗?我只想触发指定按钮上的功能。帮助我。

最佳答案

使用$('<%=btnBack.ClientID%>').click(function(){...});因为 ASP.NET 在自己的客户端上添加了控件 id 前缀,而 html 呈现的 id 可能看起来像 ct100$btnBack。

关于javascript - 允许 ASP.NET Framework 上的特定按钮上的 Javascript Onbeforeunload 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26249620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com