如何有条件地包含远程JavaScript文件? [英] How to include a remote JavaScript file conditionally?

查看:119
本文介绍了如何有条件地包含远程JavaScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML页面。

因此,根据浏览器,我需要包含一个单独的JavaScript文件。 b $ b

这怎么可能?

 < script type =text / javascript> 
if(navigator.appName =='Microsoft Internet Explorer')
{
//这里我需要包含one.js
}
else
{
//这里我需要包含two.js
}

< / script>


解决方案

最后,如果您已经在使用JQuery您的项目,只是省略了标签,您可以使用 $ .getScript


I have a HTML page.

In that, according to the browser, I need to include a separate JavaScript file.

How is it possible?

<script type="text/javascript">
if(navigator.appName == 'Microsoft Internet Explorer')
{
//here i need to include one.js
}
else
{
//here i need to include two.js
}

</script>

解决方案

And finally, if you're already using JQuery in your project and just left out the tag for it, you can use $.getScript

这篇关于如何有条件地包含远程JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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