Shot Javascript <script></script> not in TextAre

Shot Javascript <script></script> not in TextArea

本文关键字:gt script lt in TextAre not Shot Javascript      更新时间:2023-09-26

我在Javascript中有一段代码来检测屏幕的重新创建。现在我的结果(1920 x 1080)站在文本框(输入)内,但我只想要没有文本框。我需要怎么做?

法典:

<head>
<script type="text/javascript" language="javascript">
    function scrResolution() {
        var width = screen.width;
        var height = screen.height;
        document.getElementById("txt_scrWidth").value = width;
        document.getElementById("txt_scrHeight").value = height;
    }
</script>
    </head>

<body onload="scrResolution();">
  <table width="200" border="0">
     <tr>
       <td>  
 Width :
<input name="txt_scrWidth" type="text" id="txt_scrWidth" size="5" />
      </td>
     </tr>
     <tr>
       <td>
           Height :  
 <input name="txt_scrHeight" type="text" id="txt_scrHeight" size="5" />
       </td>
     </tr>
    </table>
</body>
</html>
<head>
<script type="text/javascript" language="javascript">
    function scrResolution() {
        var width = screen.width;
        var height = screen.height;
        document.getElementById("txt_scrWidth").innerHTML = width;
        document.getElementById("txt_scrHeight").innerHTML= height;
    }
</script>
    </head>

<body onload="scrResolution();">
  <table width="200" border="0">
     <tr>
       <td>  
 Width : <span id="txt_scrWidth"></span>
      </td>
     </tr>
     <tr>
       <td>
           Height :  <span id="txt_scrHeight"></span>  
       </td>
     </tr>
    </table>
</body>
</html>

也许尝试添加一个span

<table width="200" border="0">
    <tr>
        <td>Width: <span id="txt_scrWidth"></span></td>
     </tr>
     <tr>
         <td>Height: <span id="txt_scrHeight"></span></td>
     </tr>
</table>

然后使用 JavaScript 设置innerHTML

function scrResolution()
{
    var width = screen.width;
    var height = screen.height;
    document.getElementById("txt_scrWidth").innerHTML = width;
    document.getElementById("txt_scrHeight").innerHTML  = height;
}

如果您正在处理 Web 应用程序,您可能对浏览器窗口视区的大小更感兴趣。以下是您获取该信息的方法。如果用户更改屏幕大小,onresize 侦听器将起诉它已更新。

这是脚本

<script>
//make sure we update if the user resizes the browser
window.onresize = function() {
    showSize();   
};
function showSize() {
    document.getElementById("heightDisplay").innerHTML = document.height;
    document.getElementById("widthDisplay").innerHTML = document.width;
}
showSize();
</script>

这是 HTML

<div>
    Height: <span id="heightDisplay">Calculating...</span><br/>
    Width: <span id="widthDisplay">Calculating...</span>
</div>