简体   繁体   English

jQuery不会触发任何事件

[英]JQuery does not trigger any event

I have two ASP pages. 我有两个ASP页面。 One head.master which has some contents as well as contents which are retrieved from the Default.aspx page. 一个head.master ,其中包含一些内容以及从Default.aspx页检索的内容。 Because I can get script URL from the head.master page, I have it setup there along with the HTML/JQuery contents like this: 因为我可以从head.master页面获取脚本URL,所以可以在其中设置它以及HTML / JQuery内容,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
</head>
<body>
<form id="form1" runat="server">
... //other contents here
<asp:ContentPlaceHolder id="ContentPlaceHolderSearch" runat="server">
       <!-- Search stuff goes here -->
</asp:ContentPlaceHolder>
... //other contents here
</form>
</body>
</html>

In my Default.aspx page I have the contents like this: 在我的Default.aspx页面中,我的内容是这样的:

<%@ Page Language="VB" MasterPageFile="head.master" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="_default" title="WESTMED Medical Group  - Top Doctors in New York" %>
<%@ Register Assembly="Ektron.Cms.Controls" Namespace="Ektron.Cms.Controls" TagPrefix="CMS" %>
 <%@ OutputCache Duration="900" VaryByParam="none" %>
<asp:Content ID="topContent" ContentPlaceHolderID="topContent" Runat="Server">
... //other stuff goes here
</asp:Content>
<asp:Content ID="ContentPlaceHolderSearch" ContentPlaceHolderID="ContentPlaceHolderSearch" Runat="Server">
            <input style="background: url(images/find.png) no-repeat; padding-left: 20px;" type="text" id="TextBox1" />
            <input id="Button1" type="button" value="Search" class="locButton" />
            <script type = "text/javascript">
                $(document).ready(function () {
                    $("#Button1").click(function () {
                        var textbox = document.getElementById("TextBox1").value;
                        if (textbox.length > 0) {
                            //alert("Search query is not empty and redirecting...");
                            window.location.href = "http://mymed.com/search_results.aspx?searchtext=" + textbox + "&folderid=0&searchfor=all&orderby=title&orderdirection=ascending";
                        }
                        else {
                            alert("Search query is empty");
                        }
                    });
                    $('#TextBox1').keyup(function () {
                        var $th = $(this);
                        $th.val($th.val().replace(/[^a-zA-Z0-9]/g, ''));
                    });
                    $('#TextBox1').keypress(function (e) {
                        var textbox = document.getElementById("TextBox1").value;
                        var code = (e.keyCode ? e.keyCode : e.which);
                        if (code == 13) {
                            if (textbox.length > 0) {
                                e.preventDefault();
                                window.location.href = "http://mymed.com/search_results.aspx?searchtext=" + textbox + "&folderid=0&searchfor=all&orderby=title&orderdirection=ascending";
                            }
                            else {
                                e.preventDefault();
                                alert("Search query is empty");
                            }
                        }
                    });
                });
    </script> 
</asp:Content>

Looking at the output HTML source of the page I see the following: 查看页面的输出HTML源代码,我看到以下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
</head>
<body>
<form method="post" action="/" id="aspnetForm">
... //other contents goes here
<input style="background: url(images/find.png) no-repeat; padding-left: 20px;" type="text" id="TextBox1" />
            <input id="Button1" type="button" value="Search" class="locButton" />
            <script type = "text/javascript">
                $(document).ready(function () {
                    $("#Button1").click(function () {
                        var textbox = document.getElementById("TextBox1").value;
                        if (textbox.length > 0) {
                            //alert("Search query is not empty and redirecting...");
                            window.location.href = "http://mymed.com/search_results.aspx?searchtext=" + textbox + "&folderid=0&searchfor=all&orderby=title&orderdirection=ascending";
                        }
                        else {
                            alert("Search query is empty");
                        }
                    });
                    $('#TextBox1').keyup(function () {
                        var $th = $(this);
                        $th.val($th.val().replace(/[^a-zA-Z0-9]/g, ''));
                    });
                    $('#TextBox1').keypress(function (e) {
                        var textbox = document.getElementById("TextBox1").value;
                        var code = (e.keyCode ? e.keyCode : e.which);
                        if (code == 13) {
                            if (textbox.length > 0) {
                                e.preventDefault();
                                window.location.href = "http://mymed.com/search_results.aspx?searchtext=" + textbox + "&folderid=0&searchfor=all&orderby=title&orderdirection=ascending";
                            }
                            else {
                                e.preventDefault();
                                alert("Search query is empty");
                            }
                        }
                    });
                });
    </script>
... //other contents goes here
</form>
</body>
</html>

But when I press the button nothing happens. 但是当我按下按钮时,什么也没发生。 I press the enter key nothing happens. 我按回车键没有任何反应。 I can enter special characters and it doesn't do the validation. 我可以输入特殊字符,但不进行验证。 I looked at other ASPX questions and I am thinking the script does not load before the contents. 我查看了其他ASPX问题,并认为脚本不会在内容之前加载。 Please help me resolve this issue. 请帮助我解决此问题。

Console screenshot: 控制台屏幕截图:

在此处输入图片说明

Answer for everyone else's benefit: 回答所有人的利益:

As you have found, in our chat , your CMS is already using jQuery under another alias. 如您所见, 在我们的聊天中 ,您的CMS已经在另一个别名下使用jQuery。

The link you found was: Joomla 2.5 Jquery Cannot call method of null ‌​l 您找到的链接为: Joomla 2.5 Jquery无法调用null的方法

But if another jQuery is already in your CMS you will want to use that version instead. 但是,如果您的CMS中已经有另一个jQuery,则您想改用该版本。

Never assume anything when dealing with someone else's code. 处理别人的代码时,切勿假设任何东西。 Use something like Fiddler2 to view what your browser is pulling down. 使用类似Fiddler2之类的东西来查看您的浏览器正在下拉的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM