最简单的 javascript 函数不触发

发布于 2024-11-17 00:30:04 字数 1953 浏览 3 评论 0原文

    <!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>
    </form>
</body>
</html>

已更新。

我不知道为什么没有弹出窗口出现。有什么想法吗?提前致谢!

    <!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>
    </form>
</body>
</html>

Updated.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-11-24 00:30:04

尝试

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

通过这样做

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

您声明一个全局作用域的函数。在浏览器上下文中,这与执行以下操作相同:

window.checkValidity = function() { };

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() { };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文