ASP.net页
<script type="text/javascript" language="javascript">
function show_confirm() {
var r = confirm("Are you sure you want to Save this Transaction");
if (r == true) {
$('#<%=btnConfirm.ClientID%>').click();
}
else {
}
}
</script>
<asp:Content ID="detailContent" ContentPlaceHolderID="mainContentPlaceholder"
runat="server">
<asp:LinkButton ID="LinkButton1" runat="server"
CssClass="primary positive big button" OnClientClick="return show_confirm();return false"><span class="check icon"></span>Save Transaction</asp:LinkButton>
<asp:Button ID="btnConfirm" runat="server" Style="display: none;" onclick="btnConfirm_Click"/>
</content>
如果用户在弹出消息框中单击“是”,这将触发btnConfirm单击。
在IE上的页面查看源
<a onclick="return show_confirm();return false;" id="ctl00_mainContentPlaceholder_LinkButton1" class="primary positive big button" href="javascript:__doPostBack('ctl00$mainContentPlaceholder$LinkButton1','')">
<span class="check icon"></span>Save Transaction</a>
<input type="submit" name="ctl00$mainContentPlaceholder$btnConfirm" value="" id="ctl00_mainContentPlaceholder_btnConfirm" style="display: none;" />
在此致谢
最佳答案
show_confirm()
函数不返回布尔值。它应该返回一个值以使其正常工作。
为什么不像下面这样简单地执行它,它将完成您想要的?
<asp:LinkButton ID="LinkButton1" runat="server"
CssClass="primary positive big button" OnClick="LinkButton1_Click"
OnClientClick="return confirm('Are you sure you want to Save this Transaction');">
<span class="check icon"></span>Save Transaction </asp:LinkButton>
关于javascript - OnClientClick无法在IE中使用,但可以在Chrome中使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6515673/