Microsoft JScript runtime error: '$' is undefined

蹲街弑〆低调 提交于 2020-01-14 14:51:09

问题


I am trying to hide/show elements in a view using following code:

$('buttonClass/IDhere').click(function (){
$('theDivYouWantToShowClass/IDhere').toggle();
});

However, I am keep getting

Microsoft JScript runtime error: '$' is undefined

What might be the issue and how do I fix it?


回答1:


$ is defined by default when you load jquery. I would try and use jquery() to see if somehow $ is being unloaded etc. You can also load up firebug and hit the page. It should show up as a global variable/function. NOTE: You can also setup jquery to not setup the short hand "$".




回答2:


This thread is pretty old, but I think an answer in the thread would be nice. I agree with the previous two answers - it's likely because jQuery wasn't loaded. You can load it this way (usually toward the top of the file):

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

(or whatever the current version of jQuery is).

Hope it helps.




回答3:


It sounds like jQuery hasn't been loaded yet.




回答4:


did you make sure download the jquery javascript file and link in to your html/aspx page before attempting to use jquery scripting?

you need to:

  1. download the jquery code/file from: http://jquery.com/

  2. copy the file (jquery-1.8.3.min.js) you just downloaded somewhere into your web project directory/folder

  3. then insert the link to this file into html/aspx page:

  1. now try to run webpage

references: www.youtube.com/watch?v=Bf9Gs-09uzQ

www.ajaxtutorials.com/javascript/introduction-to-jquery-learn-jquery-from-scratch-in-asp-net-4-0/




回答5:


since it looks like your trying to target classes and ID's - try this

$('.buttonClass #IDhere').click(function (){
$('.theDivYouWantToShowClass #IDhere').toggle();
});



回答6:


This is a definite case of jQuery module not being loaded. In my case, common.js had a jQuery related script

$( document ).ready(function() {
var divSessionWarning = $("#idivWarn");
divSesWarning.load(divSesWarning.data("src"));
});

This was called in header.jsp. Swapping the sequence of loading the jQuery followed by the common.js resolved the issue.

<script language="javascript" type="text/javascript" src="/JAVASCRIPT/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/JAVASCRIPT/mod/common.js"></script>

Hope this helps.




回答7:


If jQuery is called then make sure jQuery is loaded before the stylesheet as its likely that calls it



来源:https://stackoverflow.com/questions/8530311/microsoft-jscript-runtime-error-is-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!