【发布时间】:2012-01-15 09:22:32
【问题描述】:
我有几个选择框让用户输入我传递到另一个页面的时间:
<p class="apptmar">
<label for="from">Appointment Starts:</label><br />
<input type="text" name="from" id="from" class="appt" /><br />
<select name="fromh" class="apptselect">
<option>1</option>
...
<option>12</option>
</select>
<select name="fromm" class="apptselect">
<option>00</option>
<option>05</option>
...
<option>55</option>
</select>
<select name="froma" class="apptselect">
<option>AM</option>
<option>PM</option>
</select>
</p>
<p class="apptmar">
<label for="to">Appointment Ends:</label><br />
<input type="text" name="to" id="to" class="appt" /><br />
<select name="toh" class="apptselect">
<option>1</option>
...
<option>12</option>
</select>
<select name="tom" class="apptselect">
<option>00</option>
..
<option>55</option>
</select>
<select name="toa" class="apptselect">
<option>AM</option>
<option>PM</option>
</select>
</p>
我想要做的是,当“约会发件人”下的一个框被更改时,“约会到”下的一个框的值被更改为相同的。我已设法使用以下方法完成此操作:
$('select[name="fromh"]').change( function() {
$('select[name="toh"]').val($(this).val());
});
这按预期工作。我现在要做的是更改分钟,但不是将其更改为相同的值,而是我希望它转到下一个。前任。 I Pick 05 under from, 10 under to 将被选中。我尝试使用以下方法,但没有成功:
$('select[name="fromm"]').change( function() {
$('select[name="tom"]').val($(this).val() + 1);
});
【问题讨论】:
-
一个小小的观察,但你没有得到 fromm 或 tom 的开场白(或者更确切地说你有,但它出现在 fromm 或 tom 之后)。
-
我已经更新了代码但是还是不行。
标签: javascript jquery html forms select