JSコードはJavascriptを
'use strict';
$(document).ready(function() {
});
function calculatePPI(inputWidth, inputHeight, inputDiagonal) {
document.getElementById("outputPPI").innerHTML=
((Math.sqrt(Math.pow('inputWidth', 2)) + (Math.pow('inputHeight', 2)))/'inputDiagonal');
}
HTMLコード
<body>
<h2>Length Converter</h2>
<p>The following program will convert your centimeters to inches.</p>
<p>
<label>Width (Pixels):</label>
<input id="inputWidth" type="number" placeholder="Width">
<p>
<label>Height (Pixels):</label>
<input id="inputHeight" type="number" placeholder="Height">
</p>
<p>
<label>Diagonal (Pixels):</label>
<input id="inputDiagonal" type="number" placeholder="Diagonal Length">
</p>
<button onclick="calculatePPI(document.getElementById('inputWidth', 'inputHeight', 'inputDiagonal').value)">Calculate</button>
</p>
<p>PPI: <span id="outputPPI"></span></p>
</body>
私はそれを計算しようとするたびに、私は、結果としてはNaNを取得していますから、結果としてNaNを取得します。
誰もがこれで私を助けてもらえますか?私はJavascriptをコーディングするのが初めてであるため、コードがどこでうまくいけないのか分かりません。
あなたは一度に3つの要素から値を取得することはできません – j08691
getElementById' 'のご使用は間違っている、すなわち'のdocument.getElementById( 'inputWidth'、 'inputHeight' 、 'inputDiagonal')。valueは動作しません。 'getElementById'を3回別々に呼び出す必要があります。 – Claies
文字列 'Math.pow( 'inputWidth'、2)'の代わりに実際の変数名を使用する必要があります: 'Math.pow(inputWidth、2)' – Brian