求大神指導(dǎo)。。。(虔誠(chéng))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>個(gè)人主頁(yè)</title>
<style type="text/css">
*{margin:0px;padding:0px;}
body{ background-image:url(../主頁(yè)圖片/14174919031526.jpg);}
#header{height:50px;background:#999999;position:fixed;top:0px;}
.wrap{width:800px;margin:0 auto;background:#999999;height:1300px;margin-top:60px;}
</style>?
<script type="text/javascript">
? ? var name=document.getElementById("header");?
? ??
? ? name.style.width=screen.availWidth; ? ?//或者sceen 添加 ?引號(hào),依舊無(wú)反應(yīng)啊
</script>
</head>
<body>
? ? ? ?<div ?id="header">
? ? ? ?
? </div>
?
? ? ? ? ? ? ? <div class="wrap">
? ? ??
? ? ? ? ? ? ? </div>
</body>
</html>
這是代碼,我設(shè)置了header的fixed屬性,使脫離了文本流,這樣寬度不能自動(dòng)適應(yīng)屏幕,我利用JavaScript中screen.availWidth獲取屏幕的寬度,再通過(guò)style.width賦值給header,為什么不成功呢??看了半天,不知道哪里出錯(cuò)了額。。
2016-06-11
我?guī)湍阏{(diào)試了下
把 var name=document.getElementById("header");?? ?
? ? name.style.width=screen.availWidth; ? ?
換成 ??document.getElementById("header").style.width=screen.availWidth+"px"
我也不能解釋不出為什么,感覺(jué)document.getElementById("header")賦值給name就變成了字符串,沒(méi)法給字符串添加屬性。你先改再等大神來(lái)答。