Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

把窗口width显示在页面上,如下代码怎么不行?谢谢

<!DOCTYPE html>
<html>
<head>
    <style>
    
    </style>
</head>
<body>
    <div class="hh">111</div>
   

</body>
    <script>
    window.onresize=function(){
        m=document.getElementsByClassName("hh")
        m.innerHTML=window.screen.width
    }
    </script>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
 window.onresize=function(){
        m=document.getElementsByClassName("hh") 
        // 注意,这个m是个集合,类数组
        m[0].innerHTML=window.screen.width
    }
    </script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...