var u = navigator.userAgent; if ((u.indexOf('Mac') > -1 || u.indexOf('Windows') > -1) && (u.indexOf('iPhone')==-1) ){ console.log('这是PC端'); }else { console.log('这是手机端'); }