简体   繁体   English

JScript运行时错误:“ $”未定义

[英]JScript runtime error: '$' is undefined

My project is in MVC 4. My scripts are in _Layout.cshtml when reload the page the following error: JScript runtime error: '$' is undefined 我的项目在MVC 4中。当重新加载页面时,我的脚本在_Layout.cshtml中,出现以下错误:JScript运行时错误:'$'未定义

_Layout.cshtml: _Layout.cshtml:

 <head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="~/Images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/bundles/jqueryui")
    <script type="text/javascript" src="~/Scripts/jquery.qtip-1.0.0-rc3.min.js"> </script>
 </head>

My Partial View: 我的局部视图:

   <script type="text/javascript">

       $('#lnkOrganizar').click(function () {
       if (($('.frozenTopC').css('display') != 'none') &&      ($('.frozenTopConteudo').css('display') != 'none')) {
           $('.frozenTopC').css('display', 'none');
           $('.frozenTopConteudo').css('display', 'none');
        }
        else {
         $('.frozenTopC').css('display', 'table-cell');
         $('.frozenTopConteudo').css('display', 'table-cell')
        }
     });

  </script>

jquery isn't present. jQuery不存在。

Look at this line: <script type="text/javascript" src="~/Scripts/jquery.qtip-1.0.0-rc3.min.js"> </script> 看这行: <script type="text/javascript" src="~/Scripts/jquery.qtip-1.0.0-rc3.min.js"> </script>

Check that you have that Scripts/jquery.qtip-1.0.0-rc3.min.js on the server 检查服务器上是否有Scripts/jquery.qtip-1.0.0-rc3.min.js

It is also NOT usual to refer to your home directory there - where you have the " ~ ". 通常也不会在该目录中引用您的主目录-您在该目录中带有“ ~ ”。 If your script is in a Scripts directory then you just use Scripts/jquery.qtip-1.0.0-rc3.min.js because with a web server, everything is within it's root (top level) directory. 如果脚本位于Scripts目录中,则只需使用Scripts/jquery.qtip-1.0.0-rc3.min.js因为对于Web服务器,所有内容都在其根(顶级)目录中。

Also is this file the main jquery library? 这也是主要的jQuery库吗? It's not clear to me whether this is just your script code and if so you'll need to include the main js library with something like: 我不清楚这是否仅是您的脚本代码,如果是,则需要在主js库中包含以下内容:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

btw, aim to use lowercase for directory names - scripts not Scripts as it will make your life easier in the long run. 顺便说一句,目标是使用小写的目录名称- scripts而不是Scripts因为从长远来看,它将使您的生活更轻松。 I would also recommend script not scripts as many directories have multiple files (their purpose after all) so most folks use singular directory. 我还建议script没有scripts多个目录多个文件(它们的目的毕竟),所以大多数人使用奇异目录。 This is closer to a preference though than the ~ issue. 尽管这比~问题更接近于偏好。

Also, while debugging and playing around, remember that you can actually have the script in the same file, within <script> tags, not in a separate file. 另外,在调试和播放时,请记住,实际上可以将脚本放在同一文件的<script>标记中,而不是单独的文件中。 Not recommended long-term as a good practice but useful for seeing where the issue is. 不建议长期将其作为一种良好做法,但对于了解问题出在哪里很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM