用户将输入摄氏度值,然后他/她将从下拉列表中选择他/她想要将其转换为的温度标度。然后,当用户单击按钮时,结果将显示在第二个文本框中。我已经尝试过了,但到目前为止,我甚至无法将结果打印在最后一个文本框中。这是我的代码:
<body>
<form name=myForm>
<p> Celcius Value
<input type="text" name="celcius" />
<p> Convert to
<select name="to" id="to">
<option></optio>
<option value="Farenheit"> Farenheit</option>
<option value="Kelvin"> Kelvin</option>
<option value="Rankine"> Rankine</option>
</select>
<hr size=2 color="blue">
<p> Click this to convert <button onclick="Converter()" />Convert</button>
<p> Result <input type="text" id="result" />
<script>
fucntion Converter() {
var celcius = document.myForm.celcius.value;
var sel = document.getEleemntById("to");
var selVal = sel.options[sel.selectedIndex].value;
if (selVal == "Farenheit") {
var result = (parseInt(celcius)*(9/5.0)) +32;
}else if ( selVal == "Kelvin") {
var result = parseInt(celcius)+273.15;
}else {
var result = (parseInt(celcius)+273.15)* (9/5.0);
}
document.getElementById("result").innerHTML= result;
}
</script>
</form>
</body>
请你好心人,请检查它有什么问题?
答案 0 :(得分:1)
你应该尝试jslint - 它可以找到你的javascript错误:
function Converter() {
var celcius = document.myForm.celcius.value;
var sel = document.getElementById("to");
var selVal = sel.options[sel.selectedIndex].value;
if (selVal == "Farenheit") {
var result = (parseInt(celcius)*(9/5.0)) +32;
}else if ( selVal == "Kelvin") {
var result = parseInt(celcius)+273.15;
}else {
var result = (parseInt(celcius)+273.15)* (9/5.0);
}
document.getElementById("result").value = result;
}