2017-09-09 22 views
0

私はこのコードを持っている:入力タイプ=テキストから値 "font-size:xxx"を取得する方法?

<style type="text/css">input[type="text"]{font-size:38px;width:700px;}</style> 
 

 
\t <p id="info"></p> 
 

 
\t <input type="text" name="tld" onkeyup="document.getElementById('info').innerHTML = 
 
\t this.value.length 
 
\t + '<hr />' 
 
\t + this.style.width 
 
\t + '<hr />' 
 
\t + this.style.fontSize;" />

が、長さのこの唯一のショーの値を、私は(フォントの)(箱の)幅とサイズを必要とします。

答えて

0

window.getComputedStyleメソッドを使用すると、探している情報を取得できます。

<style type="text/css">input[type="text"]{font-size:38px;width:700px;}</style> 
 

 
\t <p id="info"></p> 
 

 
\t <input type="text" name="tld" onkeyup="document.getElementById('info').innerHTML = 
 
\t this.value.length 
 
\t + '<hr />' 
 
\t + window.getComputedStyle(this).width 
 
\t + '<hr />' 
 
\t + window.getComputedStyle(this).fontSize;" />

関連する問題