我试图检查我的Jquery库是否加载到我的HTML页面。我正在检查它是否工作,但有些地方不太对劲。以下是我所拥有的:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/query-1.6.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if (jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
});
</script>
按照这个链接:
if (typeof jQuery == 'undefined') {
// jQuery IS NOT loaded, do stuff here.
}
there are a few more in comments of the link as well like,
if (typeof jQuery == 'function') {...}
//or
if (typeof $ == 'function') {...}
// or
if (jQuery) {
console.log("jquery is loaded");
} else {
console.log("Not loaded");
}
Hope this covers most of the good ways to get this thing done!!
按照这个链接:
if (typeof jQuery == 'undefined') {
// jQuery IS NOT loaded, do stuff here.
}
there are a few more in comments of the link as well like,
if (typeof jQuery == 'function') {...}
//or
if (typeof $ == 'function') {...}
// or
if (jQuery) {
console.log("jquery is loaded");
} else {
console.log("Not loaded");
}
Hope this covers most of the good ways to get this thing done!!