JS 코드는 자바 스크립트
'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