我试图在 ASP.NET 中名为“samples”的子文件夹中使用 jquery 库,其中母版页位于根目录中。 目前,对 jquery 脚本的引用位于母版页的 head 标签中。 如果我创建的页面也在根目录中,则一切正常。 如果我将页面移动到“samples”子目录,jquery 就会中断。
我可以通过在 head 标记中使用类似以下内容来解决该问题:
...但是后来我失去了使用 jquery intellisense 的能力,因为我在设计时不再直接连接到文件。
所以我的问题是:当我的页面位于子文件夹中并且母版页位于根目录中时,如何在 .aspx 页面上使用 jquery 库而不丢失与智能感知的连接?
I am trying to use the jquery library in ASP.NET in a subfolder called "samples" with a masterpage that is located in the root directory. Presently the references to the jquery scripts are located in the head tag of the master page. If the page I am creating is also in the root directory, everything works fine. If I move the page to the "samples" subdirectory, the jquery breaks.
I can fix the problem by using something like the following in the head tag:
<script src="<%=ResolveUrl("~/js/jquery.js")%>" type="text/javascript"></script>
...but then I lose the ability to use jquery intellisense, because I am no longer directly connected to the file in design time.
So my quesiton is this: How can I use the jquery library on a .aspx page without losing connectivity to the intellisense when my page is in a subfolder and the master page is in the root?
发布评论
评论(2)
只需使用这个:
将 / 放在 js 之前就可以了。 我总是将 css 和 javascript 文件保存在单独的文件夹中,并使用此调整来正确包含它们。
对于智能感知,你可以尝试这个技巧:
我不记得这个技巧的来源。
simply use this:
putting / before js do the trick. I always keep my css and javascript files in separate folders and use this tweak to rightly include them.
for intellisense you can try this trick:
I'm not able to recall the source of this trick.
您可以使用脚本管理器来包含 JS 文件:
You could use a script manager to include the JS files: