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

onClick and onClientClick event used together. Does not Work in Internet Explorer

本文关键字:Internet Explorer 不起作用 onClientClick 事件 一起 onClick      更新时间:2024-03-26

Java脚本代码:

<script language="javascript" type="text/javascript">
    function validateLoginForm() {
        if (document.getElementById("<%=txtTitle.ClientID%>").value == "") {
            alert("Please Enter Title");
            txtTitle.focus();
            return false;
        }
}

按钮代码

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

此代码不适用于internet explorer,但在firefox中运行良好即使javascript在onClientClick事件中返回falseonClick事件仍在被调用请帮忙。。。!!!

可以使用解决

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

用这个替换Java脚本函数

function validateLoginForm() {
        if (document.getElementById("<%=txtTitle.ClientID%>").value == "") {
            alert("Please Enter Title");
            txtTitle.focus();
            return false;
        }
        else
            return true;
}

你的OnClientClick属性与这个

OnClientClick="javascript:return validateLoginForm();"