在 ASP.NET MVC 内容占位符中使用 jQuery

发布于 2024-08-17 20:34:13 字数 1195 浏览 1 评论 0 原文

我已经在我的母版页中包含了 jQuery 以及 colorize 插件参考,并且我想在我的内容页面中使用它。 我的脚本位于 MVCApplication 的 Scripts 文件夹中。我在我的母版页中将其引用为:

与 colorize.js 相同。

在我的内容页面中,我正在为我的表格使用 colorize 插件。

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $('#mytable').colorize();
        // put all your jQuery goodness in here.
    });                    
    </script>

    <table id="mytable">
     ...
     ...
    </table>
</asp:Content>

但是每当我运行这个应用程序时,jQuery 都不起作用,colorize 函数也不起作用。

我尝试过的解决方案:

  1. 查看了 IE 7 和 jQuery.js 中的源代码& colorize.js 是正确的引用。

  2. 查看了 FF 3.5.6 和 Google Chrome 中的源代码,我发现 jquery.js 被正确引用,但 colorize.js 引用根本不包含在 HTML 中。

  3. 后来在FF中,我jQuerified我的mvc应用程序,并且所有工作正常(引用以及colorize fn)。

所以我想知道我在哪里做错了,在母版页中引用脚本文件或在内容页面中使用 colorize 插件?

也欢迎其他建议。

I have included jQuery as well as colorize plugin reference in my master page and I want to use it in my Content pages.
My scripts are located in Scripts folder in MVCApplication. I am referencing it in my master pages as :

<script language="javascript" type="text/javascript"
src="<%= Url.Content ("~/Scripts/jquery-1.3.2.min.js")%> " />

and same for colorize.js.

In my Content page, I am using colorize plugin for my table.

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $('#mytable').colorize();
        // put all your jQuery goodness in here.
    });                    
    </script>

    <table id="mytable">
     ...
     ...
    </table>
</asp:Content>

But whenever I run this application, neither jQuery works nor the colorize function work.

Solutions I tried :

  1. Viewed the source in IE 7 and jQuery.js & colorize.js are references properly.

  2. Viewed the source in FF 3.5.6 and Google Chrome, and I saw that jquery.js is referenced properly but colorize.js reference is not at all included in HTML.

  3. Later in FF, I jQuerified my mvc app, and all worked properly(references as well as colorize fn ).

So I want to know where I am doing wrong, in referencing script files in master pages or using colorize plugin in Content page?

Also other suggestions are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哑剧 2024-08-24 20:34:13

您的脚本标签需要有一个结束标签:

<script language="javascript" 
        type="text/javascript" 
        src="<%= Url.Content ("~/Scripts/jquery-1.3.2.min.js")%>" >
</script>

Your script tag needs to have a closing tag :

<script language="javascript" 
        type="text/javascript" 
        src="<%= Url.Content ("~/Scripts/jquery-1.3.2.min.js")%>" >
</script>
软的没边 2024-08-24 20:34:13
<script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.3.2.min.js " />

第一个是我的标准工作,第二个是你的。
除了语言和 /> 之外,看不出太多差异。而不是

你把它放在标题中?

<script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.3.2.min.js " />

first is standard working of me, second is yours.
Can't see much differences, besides the language and the /> in stead of

You placed it in the header?

记忆之渊 2024-08-24 20:34:13

我必须同意 adriaanp 的观点,在放置脚本时,虽然记住起来很糟糕,但这是放置结束标记的标准程序,即使您没有在其中放置任何东西。

有时,您的临时文件可能会出现问题,如果是这样,请尝试将此 colorize 插件的代码放入已经可以工作的文件中,例如 jquery 的文件,正如您所说的,这个参考文件可以工作。

我也在试图弄清楚,它发生在我的角落插件身上。我将新文件添加到解决方案中,但仍然不起作用。
当我执行此步骤时,我告诉过您,只是为了下定决心,它起作用了。
当然,我只是测试了它,然后将其放回到正确的文件中。

I have to agree with adriaanp, when putting the script, although is a bummer to remember,is standard procedure to put the closing tag even though you dont put a thing inside of it.

Sometimes as well, you can have problems with the temp files, if that's so, try to put the code of this colorize plugin in a file that already works, such as jquery's, as you told that this one's reference works.

I am trying to figure it out as well, it happened to me with the corner plugin. I added the new file into the solution, and still it not worked.
When i did this steps i told you, just to make up my mind, it worked.
Of course i just tested it and then put it back to its right file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文