到目前爲止,這是我擁有的,但無法顯示結果。我希望能夠輸入一個數字,例如「75」,點擊按鈕,然後在底部的文本框中輸入「C」等等。 到目前爲止我的代碼看起來像這樣:Javascript:將文本框中的數字條目轉換爲相應的字母等級
當我點擊「點擊這裏」我不希望答案是孤獨的,我希望它顯示在只讀文本框中。
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
var score = document.getElementById("score").value;
if (90 <= score)
{document.write ("A");}
else if (80 <= score && score < 90)
{document.write ("B");}
else if (70 <= score && score < 80)
{document.write ("C");}
else if (60 <= score && score < 70)
{document.write ("D");}
else
{document.write ("E");}
}
}
</script>
</head>
<body>
Grade % <input type="number" id="score" value=""><br>
<p><button onclick="myFunction()">CLICK HERE</button></p>
Letter Grade <input type="text" id="letter" readonly><br><br>
</body>
</html>
要顯示哪裏在頁面或輸入#字母元素中的結果? – karthick
你有一個額外的大括號支架。 – Jeremy
@karthick我希望字母等級顯示在只讀的輸入文本框中。 – anonymous