开发者

How to use jQuery on my page?

I'm foll开发者_开发百科owing this tutorial but it doesn't tell me how to run this jQuery script. Since this script will be run pretty much everywhere, I should attach this script to the Masterpage right, but how?

I guess what I'm asking is, what HTML tag do I need to reference the jQuery script, and where to put the jQuery code.

I have this library already in my project:

How to use jQuery on my page?

Thanks.


jQuery is a client-side scripting tool. ASP .Net is a server-side language.

You are correct, to add a reference to jQuery for all pages it is a good idea to use a master page for this purpose.

In the master page, you simply add the HTML script reference to the master page:

<@ MasterPage .... >

<html>
<head>
  <script src="../Scripts/jquery-1.4.1.js"></script>
</head>
<body>
 <asp:ContentPlaceHolder id="Content" />
</body>
</html>

Add a script element for each of the jQuery scripts. Make sure the jquery-1.4.1.js is the first referenced though.

Also make sure you use the <script></script> instead of <script/> due to some browser issues.

Some newer Visual Studio MVC project files do this script referencing for you (as Lenial mentioned), and this may be easier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜