如何在 ASP.NET 4 母版页中使用 jQuery
我有一个 ASP.NET 4 Web 应用程序。 我正在使用母版页 Site.Master。 母版页的标题是:
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js">
</script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js">
</script>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
目前在内容页面中,我有:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<% if (false)
{ %>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script>
<% } %>
<script type="text/javascript">
$(document).ready(function () {
alert("Welcome jQuery !");
});
</script>
<script type="text/javascript">
function Blam() { alert("Welcome jQuery !"); }; </script>
当按下“ViewButton”按钮时,我的内容页面必须显示警报! 即,ViewButton 必须调用函数 Blam! 我该怎么做?
如果我运行此代码,我会得到一个异常:
readyBound 未定义!
例外情况在文件中:jquery-1.4.4-vsdoc.js 调用堆栈是: 绑定就绪 JScript 准备好 JScript JScript 全局代码 JScript
I have an ASP.NET 4 web app.
I am using a Master Page Site.Master.
The head of the master page is:
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js">
</script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js">
</script>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
Currently in the content page, I have:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<% if (false)
{ %>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script>
<% } %>
<script type="text/javascript">
$(document).ready(function () {
alert("Welcome jQuery !");
});
</script>
<script type="text/javascript">
function Blam() { alert("Welcome jQuery !"); }; </script>
My content Page must show an alert when a button "ViewButton" is pressed!
i,e, the ViewButton must call function Blam!
How do I do that??
If I run this code, I get an exception:
readyBound is not defined!
The exception is in file: jquery-1.4.4-vsdoc.js
The call stack is:
bindReady JScript
ready JScript
JScript global code JScript
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在您的实际站点中包含
jquery-1.4.4-vsdoc.js
;它并不意味着具有功能性。当您包含
jquery-1.4.4.js
时,Visual Studio 应自动读取vsdoc
。或者,您可以将
vsdoc
包含在if (false)
中。Don't include
jquery-1.4.4-vsdoc.js
in your actual site; it is not meant to be functional.Visual Studio should automatically read that the
vsdoc
when you includejquery-1.4.4.js
.Alternatively, you can include the
vsdoc
inside anif (false)
.您不需要在网页上包含 vsdoc 文件 - 它只需要与 jquery 文件位于同一文件夹中,并且只为 Visual Studio 提供智能感知。
You don't need to include the vsdoc file on your web page - it just needs to be in the same folder as your jquery file and just provides intellisense for Visual Studio.