gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:00:37 26 4
gpt4 key购买 nike

我正在为这个网站编码,并且我需要在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com