我希望用户从公制切换到英制时标签能够改变。
它可以正确检测到更改并存储当前选择的值,进入if语句,但之后没有任何反应。
以下是我的JavaScript代码。
它可以正确检测到更改并存储当前选择的值,进入if语句,但之后没有任何反应。
以下是我的JavaScript代码。
$(document).ready(function()
{
$("select[name = unit]").change(function()
{
var selected = $("option:selected", this).text();
if(selected == "Metric (cm)")
{
$("label[for = unit]").text("mm");
}
else if(selected == "Imperial (inches)")
{
$("label[for = unit]").text("in");
}
});
})
And my html.
<form name ="Calculator">
Unit of Measurement:
<select name = "unit">
<option value = "120904000">
Metric (cm)
</option>
<option value = "4760000">
Imperial (inches)
</option>
</select>
<br>
Root Diameter: <input type = "text" name = "root" autocomplete = "off">
<label for = "unit"></label>
<br>
Width between bearings: <input type = "text" name = "bearings" autocomplete = "off">
<label for = "unit"></label>
<br>
End Fixity:
<select name = "fixity">
<option value = ".36">
1
</option>
<option value = "1.0">
2
</option>
<option value = "1.47">
3
</option>
<option value = "2.23">
4
</option>
</select>
<br>
Max Speed (RPM): <input type = "text" name = "speed" autocomplete = "off"><br>
<a href = "#" class = "reset" onclick = "">Reset</a>
<a href = "#" class = "calculate" onclick = "checkOp(); return(false);">Calculate</a>
<a href = "#" class = "close" onclick = "">Exit</a>
</form>
for = unit
的属性,带有所有这些空格? - adeneo