0

画面の解像度を検出するための 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>
4

3 に答える 3

2

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>

次に、innerHTMLJavaScriptを使用して設定します。

function scrResolution()
{
    var width = screen.width;
    var height = screen.height;
    document.getElementById("txt_scrWidth").innerHTML = width;
    document.getElementById("txt_scrHeight").innerHTML  = height;
}
于 2013-01-24T13:21:06.667 に答える
2
<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>
于 2013-01-24T13:22:11.047 に答える
0

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>
于 2013-01-24T13:32:19.780 に答える