[英]onClick and onClientClick event used together. Does not Work in Internet Explorer
Java script code: Java脚本代码:
<script language="javascript" type="text/javascript">
function validateLoginForm() {
if (document.getElementById("<%=txtTitle.ClientID%>").value == "") {
alert("Please Enter Title");
txtTitle.focus();
return false;
}
}
Button Code 按钮代码
<asp:Button ID="btnPost" UseSubmitBehavior="false" Text="Post" OnClientClick="javascript:validateLoginForm();" runat="server" OnClick="btnPost_Click" />
This code is not working on internet explorer but works fine in firefox even though the javascript returns false in onClientClick event the onClick event is still getting called Please Help...!!! 此代码不能在Internet Explorer上运行,但在firefox中工作正常,即使javascript在onClientClick事件中返回false,onClick事件仍然被调用请帮助... !!!
它可以使用
<asp:Button ID="btnPost" UseSubmitBehavior="false" Text="Post" OnClientClick="return validateLoginForm();" runat="server" OnClick="btnPost_Click" />
Replace your Java script function with this 用这个替换你的Java脚本函数
function validateLoginForm() {
if (document.getElementById("<%=txtTitle.ClientID%>").value == "") {
alert("Please Enter Title");
txtTitle.focus();
return false;
}
else
return true;
}
And you OnClientClick attribute with this 而你OnClientClick属性与此
OnClientClick="javascript:return validateLoginForm();"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.