javascript - 如何为此脚本编写其他内容

标签 javascript jquery html mobile responsive-design

我正在为这个网站编码,并且 我需要在 pc-view 和 mobile-view 的两个脚本之间更改 javascript。 我在网上找到了这段代码,它确实在移动 View 上加载了特定脚本,但我想在 PC 上查看时切换到另一个脚本。

因此,我需要知道如何编写以下脚本的“else”部分,以便我可以加载“pc”版本。

<!--
if (navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0) {
//what u want to run in mobile devices 
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "js/script_photo_sp.js";//file directory
document.getElementsByTagName("head")[0].appendChild(s);}
alert(s.src);//for running test purposes
//-->

任何帮助将不胜感激!

最佳答案

在本例中,在此行的末尾查找大括号

document.getElementsByTagName("head")[0].appendChild(s);} // end of condition
else {
   // else code goes here
}

关于javascript - 如何为此脚本编写其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32633318/

相关文章:

javascript - 长数组的对象解构解决方案?

javascript - super 简单的 jQuery 选项卡 - 没有 UI - 页面加载时折叠

javascript - 从事件处理程序调用方法

javascript - 使 bootstrap popover 出现在与其触发器不同的元素上

javascript - 在 Javascript 或 jQuery 中,如何检测特定标签是否存在?

html - 如何在没有固定高度的情况下将条形图条附加到底部

javascript - 使用回收帧缓冲区的 threejs 片段着色器

javascript - 如何将 key 添加到添加到 Angularfire 2 版本 5 中节点的对象

javascript - 单击按钮时如何删除 css 部分

javascript - 使用函数绑定(bind)将值从一个指令传递到另一个指令 '&'