实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="" id="link"> </head> <body> <div id="box"></div> </body> <script> document.write('屏幕的宽度:'+window.screen.width+'<br/>'); document.write('屏幕的高度:'+window.screen.height+'<br/>'); //获取屏幕的宽度 w=window.screen.width; var link = document.getElementById('link'); switch(w){ case 1280: link.href="a.css"; break; case 1024: link.href="b.css"; break; } document.write('文档可用高度:'+window.innerHeight+'<br/>'); document.write('文档可用宽度:'+window.innerWidth+'<br/>'); </script> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例