包括jQuery(如果尚未包括) [英] Include jQuery, if not included already

查看:92
本文介绍了包括jQuery(如果尚未包括)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将jquery包含在文件中(如果页面中尚未包含). 我该怎么办?

I want to include the jquery in file, if not included already in the page. How can I do this?

我写了这个,但是却给出了不希望的输出.

I wrote this, but it's giving undesired output.

<script type="text/javascript">
if ('undefined' == typeof window.jQuery) {
    // jQuery not present
//  alert("Jquery Unavailable");
<?php echo '<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>'; ?>
} else {
    // jQuery present
    alert("Jquery Available");
}
</script>

推荐答案

您无法在PHP中做到这一点.试试这个

you cant do that in PHP. Try this instead

<script type="text/javascript">

if(typeof jQuery == 'undefined'){
        document.write('<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></'+'script>');
  }

</script>

这篇关于包括jQuery(如果尚未包括)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆