admin管理员组文章数量:1401199
My project is in MVC 4. My scripts are in _Layout.cshtml when reload the page the following error: JScript runtime error: '$' is undefined
_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>
My project is in MVC 4. My scripts are in _Layout.cshtml when reload the page the following error: JScript runtime error: '$' is undefined
_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>
Share
Improve this question
edited Oct 6, 2013 at 22:50
Michael Durrant
96.7k101 gold badges347 silver badges531 bronze badges
asked Sep 24, 2013 at 12:40
DanielleDanielle
1392 gold badges4 silver badges19 bronze badges
8
- Please check if your jQuery is loading properly. Otherwise there is no other reason for this error. – Ganesh Pandhere Commented Sep 24, 2013 at 12:41
- 1 Are you sure that jQuery has been included? E.g. if you view the source of the final output, does it successfully resolve the link to jQuery? – Moo-Juice Commented Sep 24, 2013 at 12:41
- Does the rendered code has a working link to the jQuery library? – Clyde Lobo Commented Sep 24, 2013 at 12:43
-
be sure to wrap your script in
$(window).load(function(){});
to be sure your script run when the page is ready, and not before the jquery is loaded and make sure, jquery loaded beforejtip
– Iliya Reyzis Commented Sep 24, 2013 at 12:46 - 1 Open the dev tools in your browser. Look at the HTML code: Is the jQuery lib in your page? Is the URL correct? Is there a 404 error for it? (or any other error?) – Spudley Commented Sep 24, 2013 at 12:48
1 Answer
Reset to default 3jquery isn't present.
Look at this line: <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
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.
Also is this file the main jquery library? 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:
<script src="//ajax.googleapis./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. I would also remend script
not scripts
as many directories have multiple files (their purpose after all) so most folks use singular directory. 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. Not remended long-term as a good practice but useful for seeing where the issue is.
本文标签: javascriptJScript runtime error 3939 is undefinedStack Overflow
版权声明:本文标题:javascript - JScript runtime error: '$' is undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744233982a2596471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论