模拟“include_once”对于jQuery [英] Simulate an "include_once" for jQuery

查看:84
本文介绍了模拟“include_once”对于jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用jQuery的简单页面,因此包含jquery.min.js。



但是我必须在同一页面插入一个iFrame ,不幸的是我不能使用任何其他的东西),包括jquery.min.js的不同版本。



如何强制浏览器只包含其中的一个版本(如php中的include_once)?



谢谢!

解决方案

未经测试,但在页面结尾处,位于< / body> 标记之前,您可以添加以下内容:

 < script> 
window.jQuery || document.write('< script src =js / jquery.min.js>< \ / script>')
< / script>

这会检查jQuery是否可用,如果不是,它将从指定的路径动态添加一个。 / p>

I have created a simple page that use jQuery, so include jquery.min.js.

But I have to insert an iFrame in the same page (and no, unfortunately I can't use anything else) that include a different versione of jquery.min.js.

How can I force the browser to include only one of those two version (like an include_once in php)?

Thank you!

解决方案

Not tested but at the end of your page, just before </body> tag, you can add this:

<script>
  window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

This checks if jQuery is available or not, if not it will add one dynamically from path specified.

这篇关于模拟“include_once”对于jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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