运行一下代码后,效果就是:您显示器的分辨率为:undefined 像素 x undefined 像素这是为什么?应该如何更改?谢谢
<html>
<head>
<title>主页</title>
<script type="text/javascript" language="javascript">
function screen(){
alert('您显示器的分辨率为:\n' + screen.width + '×' + screen.height + ' 像素');
}
</script>
</head>
<body>
<input type="button" value="获得分辨率" onclick="screen()" /></a>
</body>
</html>
<html>
<head>
<title>主页</title>
<script type="text/javascript" language="javascript">
function screen(){
alert('您显示器的分辨率为:\n' + screen.width + '×' + screen.height + ' 像素');
}
</script>
</head>
<body>
<input type="button" value="获得分辨率" onclick="screen()" /></a>
</body>
</html>
window.screen.availHeight //在windows里会减去任务栏的高度
alert('您显示器的分辨率为:\n' + window.screen.width + '×' + window.screen.height + ' 像素');
写全试试