HTML
<table>
<tr>
<td style="align-content: center">
<select id="start-lunch-hour" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-hour" tabindex="-1" data-inline="true" data-icon="false">
<option value="13">--</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12" selected="selected">12</option>
</select>
</td>
<td style="align-content: center">
<fieldset data-role="controlgroup" data-type="horizontal">
<select id="start-lunch-minute-digit1" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-minute-digit1" tabindex="-1" data-scroll="true" data-inline="true" data-icon="false">
<option value="13">--</option>
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<select id="start-lunch-minute-digit2" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-minute-digit2" tabindex="-1" data-scroll="true" data-inline="true" data-icon="false">
<option value="13">--</option>
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</fieldset>
</td>
</tr>
</table>
jQuery
$(function () {
$("#start-time-hour").change(function () {
var data = $(this).find(":selected").val();
//alert(data);
if (data == 13) {
// This field will be output.
if ($("#start-time-minute-digit1").find(":selected").val() != 13) {
$("#start-time-minute-digit1").val(13).prop('selected', true);
}
if ($("#start-time-minute-digit2").find(":selected").val() != 13) {
$("#start-time-minute-digit2").val(13).prop('selected', true);
}
//alert($("#start-time-minute-digit1").find(":selected").val());
//alert($("#start-time-minute-digit2").find(":selected").val());
}
else {
// This is normal digit input value selection for time from dropdown.
}
});
});
有三个选择(值属性与显示的文本相同) start-time-hour options --,0,1,2.....9 start-time-minute-digit1 options --,0,1,.. .5 start-time-minute-digit2 选项 --,0,1,2.....9
在将其中任何一个更改为“--”选项时,其他两个必须更改为“--”。我写了上面的函数。调试显示值已更改,但页面上的显示文本未更新。当前在 .net C# mvc3 中使用 jQuery mobile。