onClick和onClientClick事件一起使用。在Internet Explorer中不起作用

时间:2021-04-19 06:56:15

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事件仍然被调用请帮助... !!!

2 个解决方案

#1


2  

It can be solved using

它可以使用

<asp:Button ID="btnPost"  UseSubmitBehavior="false"  Text="Post" OnClientClick="return validateLoginForm();" runat="server" OnClick="btnPost_Click"  />

#2


0  

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();"

#1


2  

It can be solved using

它可以使用

<asp:Button ID="btnPost"  UseSubmitBehavior="false"  Text="Post" OnClientClick="return validateLoginForm();" runat="server" OnClick="btnPost_Click"  />

#2


0  

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();"