简体   繁体   English

jQuery在Visual Studio 2008中不起作用

[英]jQuery is not working in Visual Studio 2008

I'm new to jQuery.. I'm using Visual Studio 2008.. In that I tried basic jQuery function.. But its not working.. My script coding is: 我是jQuery的新手。我正在使用Visual Studio 2008。.那我尝试了基本的jQuery函数..但是它不起作用..我的脚本编码是:


<title>
<script src="jquery-1.2.6.js" type="text/javascript" />
<script src="jquery-1.2.6-vsdoc.js" type="text/javascript" />
<script src="jquery-1.2.6.min.js" type="text/javascript" />
<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" />
<script type="text/javascript">
    $(document).ready( function(){
    $("#Button1").click(function(){
    alert("Hello");
    });
    });
</script>

And my asp coding is: 我的asp编码是:


<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>

Can anyone tell my why its not working? 谁能告诉我为什么它不起作用?

You are including jquery multiple times on the page - both minified and regular versions. 您在页面上多次包含jquery-缩小版和常规版。

Reduce it to just one. 减少到一个。

Use only one jquery js file. 仅使用一个jquery js文件。

remove this jquery file 删除这个jQuery文件

<script src="jquery-1.2.6.min.js" type="text/javascript" />
<script src="jquery-1.2.6.js" type="text/javascript" />

and use only 只使用

<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" 

this will work. 这将起作用。

and use button like this if you are just performing jquery operation 并使用这样的按钮(如果您只是执行jquery操作)

<input type="button" ID="Button1" Text="Button" />
  1. Don't use script tag autoclose! 不要使用脚本标签自动关闭!
  2. Ad only one jquery reference. 仅广告一个jquery参考。
  3. Make sure that your button ID in resulting html doesn't changed? 确保您生成的html中的按钮ID没有更改?

When you are using the control from server side(asp controls).Use ClientID to get that control 从服务器端使用该控件(asp控件)时,请使用ClientID获取该控件

$(document).ready( function(){
    $("#<%=Button1.ClientID%>").click(function(){
    alert("Hello");
    });
});

You can try after removing first three libraries: 您可以在删除前三个库后尝试:

<script src="jquery-1.2.6.js" type="text/javascript" />
<script src="jquery-1.2.6-vsdoc.js" type="text/javascript" />
<script src="jquery-1.2.6.min.js" type="text/javascript" />

and plz don't try doing inline closing of script: 和PLZ不要尝试内联关闭脚本:

<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript">
</script>

modify your first block of code as below: 修改您的第一段代码,如下所示:

<title>My Test Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"        type="text/javascript" ></script>
<script type="text/javascript">
    $(document).ready( function(){
      $("#<%=Button1.ClientID%>").click(function(){
        alert("Hello");
      });
    });
</script>

it will work. 它会工作。

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

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