87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>演示代码</title>
</head>
<body>
<div id="news_bottom">
</div>
</body>
</html>
$(document).ready(function () {
if ($("#currentDevice").val() == "wap") {
loadScript("news_bottom", "http://xxx.com/a.js");
}
else
{
loadScript("news_bottom", "http://xxx.com/b.js");
}
});
//加载js
var loadScript=function(id,scriptLink)
{
var obj = document.getElementById(id);
var oScript = document.createElement("script");
oScript.type = "text/javascript";
oScript.src = scriptLink;
obj.appendChild(oScript);
}
<div id="news_bottom">
if(移动端)document.write('<script src="移动端js路径"><\/script>')
else document.write('<script src="pc端js路径"><\/script>')
</div>
$(function(){
var url;
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios|SymbianOS|Windows Phone|BlackBerry)/i)) {
url = 'http://xxx.com/a.js';
}else{
url = 'http://xxx.com/b.js';
}
$("<script>").attr("src", url).appendTo("#news_bottom");
})
<div id="news_bottom">
<script type="text/javascript">
(function(){
var url;
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios|SymbianOS|Windows Phone|BlackBerry)/i)) {
url = 'http://xxx.com/a.js';
}else{
url = 'http://xxx.com/b.js';
}
document.write("<scr" + "ipt src='" + url + "' type='text/javascript'></scr" + "ipt>");
})()
</script>
</div>