当用户从下拉列表中选择一个选项时,我试图更改 span 的值,但这似乎不起作用。
HTML:
<tr>
<td class="field" colspan="4">
<select id="mmt">
<option value="Metric" selected>METRIC</option>
<option value="English">ENGLISH</option>
</select></td>
</tr>
<tr>
<td class="head"><label for="abc">ABC</label></td>
<td class="field"><input type="text" id="abc"/><span class="m">MM</span> OD</td>
<td class="head"><label for="pqr"></label></td>
<td class="field"><input type="text" id="pqr" /><span class="ms">MM</span></td>
</tr>
<tr>
<td class="head"><label for="xyz">XYZ</label></td>
<td class="field"><input type="text" id="xyz" /></td>
<td class="head"><label for="stu"></label></td>
<td class="field"><input type="text" id="stu"/><span class="ms">MM</span></td>
</tr>
jQuery:
$(function() {
$('#mmt').change(function() {
if ($('#mmt option:selected').text() == "English") {
$('.ms').text("INCH");
}
else {
$('.ms').text("MM")
}
});
});