宽屏、标屏页面切换,遗憾的是切换一次后就切换不了了,请赐教!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>宽屏、标屏页面切换</title>
<style>
body { margin:0;}
#bigWidth { width:100%;}
#normalWidth { width:950px; margin:0 auto;}
.top { width:100%; height:60px; background:#666; overflow:hidden;}
.left { width:25%; height:200px; float:left; background:#09C;}
.right { width:75%; height:200px; float:right; background: #66C;}
.foot { width:100%; height:50px; background:#CCC;}
.clear { clear:both;}.top span { display:block; margin:20px; width:100px; height:30px; background:#960; cursor:pointer;}
</style>
</head><body>
<script>
function addLoadEvent(func){
var onload=window.onload;
if(typeof window.onload !="function"){
window.onload=func;
}else{
window.onload=function(){
oldonload();
func();
}
}
}
function WS(){
var SB=document.getElementById("SB");
var bigWidth=document.getElementById("bigWidth");
var bigId=bigWidth.getAttribute("id");
SB.onclick=function(){
//alert("test");
bigWidth.setAttribute("id","normalWidth");
SB.innerHTML="宽屏";
}
}addLoadEvent(WS);
</script><div id="bigWidth">
  <div class="top"><span id="SB">标屏</span></div>
  <div class="left"></div>
  <div class="right"></div>
  <div class="clear"></div>
  <div class="foot"></div>
</div>
</body>
</html>

解决方案 »

  1.   

    这段代码你写的?function WS(){
        var SB=document.getElementById("SB");
        var bigWidth=document.getElementById("bigWidth");
        var bigId=bigWidth.getAttribute("id");
        SB.onclick=function(){
            //alert("test");
    if(bigWidth.id=="bigWidth"){
    bigWidth.setAttribute("id","normalWidth");
    SB.innerHTML="宽屏";
    }else{
    bigWidth.setAttribute("id","bigWidth");
    SB.innerHTML="标屏";
    }
        }
    }
      

  2.   

    我的想法是if if(bigId=="bigWidth"){
                bigWidth.setAttribute("id","normalWidth");
                SB.innerHTML="宽屏";
            }else{
                normalWidth.setAttribute("id","bigWidth");
                SB.innerHTML="标屏";
            }
    你看下我的这个想法哪里有问题?
      

  3.   

    我之前的想法是在if里面加入onclick