检查是否使用Javascript加载了jquery我正在尝试检查我的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>
3 回答

qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
if (typeof jQuery == 'undefined') { // jQuery IS NOT loaded, do stuff here.}
if (typeof jQuery == 'function')//orif (typeof $== 'function')
和
if (jQuery) { alert("jquery is loaded");} else { alert("Not loaded");}
希望这能涵盖完成这项工作的所有好方法!

杨魅力
TA贡献1811条经验 获得超6个赞
if ('undefined' == typeof window.jQuery) {
// jQuery not present
} else {
// jQuery present
}
添加回答
举报
0/150
提交
取消