问题
Suppose I have the following html:
<div id="test1">hi</div>
<a href="#" onclick="showDiv()">click here</a>
and the javascript:
function showDiv() {
$("#test1").hide();
}
When I try it on jsfiddle, it returns:
$ is not defined
Did I miss some setting in jsFiddle?
Thanks.
回答1:
That suggests that you have not selected one of the jQuery libraries from the left hand side of the screen.
回答2:
These answers are old and for anyone looking for an updated version the dropdown menu is now located on the gear next to the word Javascript at the top right of your javascript window in jsfiddle.
回答3:
Screenshot of the current (Dec 2015) version of jsfiddle:
I just wasted a lot of time on this silly error as well - frameworks and extensions are now selected via the "JAVASCRIPT *" button in the JavaScript pane!
回答4:
Either do what @Drew and @James show.
if you remain having problems (which I know I did the other day), you can add an external resource from a CDN library
"http://code.jquery.com/jquery-1.9.1.min.js"
good luck !
回答5:
If anyone is reading this in 2017, then make sure to add the jQuery link using https protocol. This is to be added in the External resources tab present at the left of the page.
回答6:
$("#test1").hide();
the above is not defined meaning the $
Example.
jQuery(document).ready(function($) {
$("#test1").hide();
}
`
jQuery(document).ready(function(IsNowDefined) // just for explanation
IsNowDefined("#test1").hide();
来源:https://stackoverflow.com/questions/15468340/is-not-defined-in-jsfiddle