方法1:css的方式
@media (min-width: 768px ){
.mobilexs{
/*手机显示*/
}
.pcxs{
/*电脑不显示*/
display:none;
}
}
@media (min-width: 1200px) {
.mobilexs{
/*手机不显示*/
display:none;
}
.pcxs{
/*电脑显示*/
}
}
方法2:js自动判断
<meta http-equiv="mobile-agent" content="format=xhtml;url=手机网站">
<script type="text/javascript">
//手机版跳转
if(window.location.toString().indexOf('pref=padindex') != -1)
{}
else
{
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent)))
{
if(window.location.href.indexOf("?mobile")<0)
{
try
{
if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent))
{window.location.href="手机网站";}
else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}
</script>
方法3:js点击判断
<script language="JavaScript">
//写一个判断函数
function ScreenWidth() { //获取屏幕尺寸,判断PC端或移动端
if (/phone|pad|pod|iPhone|iPod|ios|iPad|Android|Fennec|BlackBerry|Mobile|IEMobile|MQQBrowser|JUC|Fennec|WosBrowser|BrowserNG|WebOS|Symbian|Windows Phone/i.test(navigator.userAgent)) {
//如果是移动端,则跳转到移动端对应的页面;否则,跳转到PC端对应的页面
window.location.href = './mobile/html/index.html';
} else {
window.location.href = './pc/static/template/index.html';
}
}
//第一种方式,通过点击屏幕的方式,调用函数,进行页面跳转
document.body.onclick = function() {
ScreenWidth()
}
//第二种方式,等待页面加载完成,调用函数,进行自动跳转(但是在网速较慢的情况下,可能动画或者内容还没加载完成,就自动跳转咯)
window.οnlοad=function(){
ScreenWidth()
}
</script>