jQuery的使用母版页的ASP.net MVC应用程序 [英] jQuery in an ASP.net MVC application using Master Pages
问题描述
我试图让简单的jQuery与以下没有运气我的内容网页上执行的是什么,我试图做的:
< ASP:内容ID =内容1ContentPlaceHolderID =日程地址搜索Maincontent=服务器> <脚本SRC =../../脚本/ jQuery的-1.2.6.js的TYPE =文/ JavaScript的>< / SCRIPT>
<脚本类型=文/ JavaScript的> $(文件)。就绪(函数(){
警报(HI);
});
< / SCRIPT>< / ASP:内容>
我也试图得到以下工作:
< ASP:内容ID =内容1ContentPlaceHolderID =日程地址搜索Maincontent=服务器> <脚本SRC =../../脚本/ jQuery的-1.2.6.js的TYPE =文/ JavaScript的>< / SCRIPT>
<脚本类型=文/ JavaScript的>
函数的onload()
{
$(#myDiv),CSS(边界,固体1px的绿色)。
}
< / SCRIPT> < DIV ID =myDive>
你好
< / DIV>< / ASP:内容>
这可能是JQuery的文件无法找到,尝试一下本作的脚本引用:
< SCRIPT SRC =<%= Url.Content(〜/脚本/ jQuery的-1.2.6.js的)%>中类型=文/ JavaScript的>< / SCRIPT>
该Url.Content将应用程序是否在根或子目录中运行构建正确的路径,无论
另外,如果你已经安装了热修复的JS智能感知,除了可以使用上面:
<如果%(假){%GT;
<! - 不要把这个包是Url.Content通话,是这样的,所以我们获得智能! - >
<脚本SRC =../../脚本/ jQuery的-1.2.6-vsdoc.js类型=文/ JavaScript的>< / SCRIPT>
<%}%GT;
编辑:
由于RC 1刷新的发行版中,已经有知道是不是BUG有关放置与code块元素在标题中,菲利普Haacked有一个很好的<一个href=\"http://haacked.com/archive/2009/01/27/controls-collection-cannot-be-modified-issue-with-asp.net-mvc-rc1.aspx\">article关于解决它......
编辑2:
显然,这已得到修复,因为RC 2发布...
•code掘金是头元素的直接子不会导致异常如果=服务器属性添加到他们。
块引用>修改3:
的热修复较早引用的是只适用于VS2008和可用这里 - 由VS网络开发团队<一检查出的博客文章href=\"http://blogs.msdn.com/webdevtools/archive/2008/02/08/jscript-intellisense-working-with-jquery.aspx\">here了解详情。 VS2010有它内置的。
I am trying to get simple jQuery to execute on my Content page with no luck below is what I am trying to do:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { alert("hi"); }); </script> </asp:Content>
I have also tried getting the following to work:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script> <script type="text/javascript"> function onload() { $("#myDiv").css("border", "1px solid green"); } </script> <div id="myDive"> Hello </div> </asp:Content>
解决方案It may be that the JQuery file can't be found, try this for the script reference:
<script src="<%= Url.Content ("~/Scripts/jquery-1.2.6.js") %>" type="text/javascript"></script>
The Url.Content will build the correct path regardless of whether the app is running in the root or a sub-directory.
Also, if you've installed the hot-fix for the JS intellisense, you can use this in addition to the above:
<% if (false) { %> <!-- Don't wrap this is a Url.Content call, it's like this so we get intellisense! --> <script src="../../Scripts/jquery-1.2.6-vsdoc.js" type="text/javascript"></script> <% } %>
Edit:
Since the release of the RC 1 Refresh, there's been a know bug about placing elements with code blocks in the header, Philip Haacked has a nice article about solving it...
Edit 2:
Apparently this has been fixed since RC 2 was released...
• Code nuggets that are direct children of the head element do not cause an exception if the runat="server" attribute is added to them.
Edit 3:
The hot-fix referenced earlier is only applicable to VS2008 and is available here - check out the blog post by the VS Web Dev Team here for details. VS2010 has it built in.
这篇关于jQuery的使用母版页的ASP.net MVC应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!