遇到一个问题,抽调出来一个js供其他子系统使用,但是在该js里需要使用jquery.js,但是其他系统在引入抽调出来的js时,会覆盖掉他们自己重写的对象方法等,所以需要动态判断,
<script>
if (typeof (jQuery) == 'undefined') {
document.write("<script language=javascript src='a.js'></script>");
}else{
document.write("<br><<<<<<<<<<<<<<<<<<<<<<<<<<<,,,,................<br>");
}
</script>
上面的方法会出错,主要是因为</script>会匹配离他最近的<script>,引号“”无法限制住结束标签,所以使用时,可以使用:
<script type="text/javascript" src="http://localhost/UC/a.js"></script>
a.js里:
document.write('<script type="text/javascript" src="http://localhost/UC/themes/default/public/js/jquery.js"></script>');