Javascript JQuery不会触发任何事件

Javascript JQuery不会触发任何事件,javascript,jquery,html,asp.net,Javascript,Jquery,Html,Asp.net,我有两个ASP页面。一个head.master,其中包含一些内容以及从Default.aspx页面检索的内容。因为我可以从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

我有两个ASP页面。一个
head.master
,其中包含一些内容以及从
Default.aspx
页面检索的内容。因为我可以从
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>
<%@ 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>
查看页面的输出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>

... //其他内容在这里
$(文档).ready(函数(){
$(“#按钮1”)。单击(函数(){
var textbox=document.getElementById(“TextBox1”).value;
如果(textbox.length>0){
//警报(“搜索查询不为空,正在重定向…”);
window.location.href=”http://mymed.com/search_results.aspx?searchtext=“+textbox+”&folderid=0&searchfor=all&orderby=title&orderdirection=ascending”;
}
否则{
警报(“搜索查询为空”);
}
});
$('#TextBox1').keyup(函数(){
var$th=$(本);
$th.val($th.val()。替换(/[^a-zA-Z0-9]/g');
});
$('#TextBox1')。按键(功能(e){
var textbox=document.getElementById(“TextBox1”).value;
var代码=(e.keyCode?e.keyCode:e.which);
如果(代码==13){
如果(textbox.length>0){
e、 预防默认值();
window.location.href=”http://mymed.com/search_results.aspx?searchtext=“+textbox+”&folderid=0&searchfor=all&orderby=title&orderdirection=ascending”;
}
否则{
e、 预防默认值();
警报(“搜索查询为空”);
}
}
});
});
... //其他内容在这里
但当我按下按钮时,什么也没发生。我按下回车键,什么也没发生。我可以输入特殊字符,但它不进行验证。我看了其他的ASPX问题,我认为脚本不会在内容之前加载。请帮我解决这个问题

控制台屏幕截图:

为所有其他人的利益而回答: 正如您所发现的,您的CMS已经在另一个别名下使用jQuery

您找到的链接是:

但是,如果您的CMS中已经有另一个jQuery,您将希望使用该版本


在处理其他人的代码时,不要假设任何东西。使用类似的工具查看您的浏览器正在下拉的内容。

您的控制台中是否存在任何javascript错误?能否在chrome F12中打开并在此处显示网络窗格的屏幕截图?听起来$不是jQuery,因为$(“#id”)永远不会返回空值。您确实应该更新该jQuery版本。从2009年2月开始。这是非常过时的。由于ASP只是大量生产原始HTML页面,这是一个小坚果。。。您注释掉的部分中还有Javascript吗?请在链接中添加
Fiddler2
,以便于访问:)谢谢!帮了大忙!!!