对于不同设备显示的样式最好还是使用媒体查询的方式,不过如果想要分别引入css文件也是可以的。
要设置引入不同的js文件也可以使用这种方式。
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {//判断访问环境是 移动端 则加载以下样式headAppendCss("./css/mobile_index.css");headAppendCss("./css/mobile_footer.css");} else {headAppendCss("./css/pc_index.css");headAppendCss("./css/pc_footer.css");}function headAppendCss(href) {var link = document.createElement("link");link.type = "text/css";link.rel = "stylesheet";link.href = href;$("head").append(link);}
