开发者

Simplest javascript function not firing

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jQueryValidation.Default" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.6.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    function checkValidity() {
        var container = document.getElementById("toggle");
        alert("uspeh!");
        var inputArray = container.getElementsByTagName("input");
    }
    </script>   
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="toggle">
        <asp:Label ID="lblName" runat="server" Text="Vnesi ime: "></asp:Label>
        <span><asp:TextBox ID="txtName" runat="server" data-errormessage="Внесете име" data-class="required"></asp:TextBox></span>
        <br />
        <asp:Label ID="lblSurname" runat="server" Text="Vnesi prezime: "></asp:Label>
        <span><asp:TextBox ID="txtSurname" runat="server" data-errormessage="Внесете презиме" data-class="required"></asp:TextBox></span>
        <br />
        <asp:Label ID="lblNickname" runat="server" Text="Vnesi nadimak: "></asp:Label>
        <span><asp:TextBox ID="txtNickname" runat="server" data-errormessage="Внесете надимак" data-class="required"></asp:TextBox></span>
        <br /><br />
        <asp:Button ID="btnSend" runat="server" Text="Send" 
            OnClientClick="checkValidity(); return false;" onclick="btnSend_Click" />
    </div>
    </开发者_StackOverflowform>
</body>
</html>

Updated.

I have no idea why no pop-up shows up. Any idea? Thanks in advance!


Try

<asp:button text="Click me" onclientclick="window.checkValidity();" />

By doing

<script language="javascript" type="text/javascript">
    function checkValidity() { }
</script> 

You declare a function to the global scope. In the context of a browser it is the same as doing:

window.checkValidity = function() { };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜