开发者

jQuery UI Open Dialog run Function

This is the gist of what I am trying to accomplish with this code. I want to select an HOUR ahead, which this code Does do that, it just selects 4 items down. BUT my major problem is, say if someone selects 11:30pm, or 12 midnight, my .NEXT() code doesn't work... Is there a better solution for this?

$('.startTime222').change(function() {
   adjustTime = $(".startTime option:selected").next().next().next().next().val(); 
});

<select name="startTime" class="startTime222 required" id="startTim开发者_JAVA技巧e2" >
   <option value="00:00:00">12:00am</option>
   <option value="00:15:00">12:15am</option>
   <option value="00:30:00">12:30am</option>
   <option value="00:45:00">12:45am</option>
   <option value="01:00:00">1:00am</option>
   <option value="01:15:00">1:15am</option>
   <option value="01:30:00">1:30am</option>
   <option value="01:45:00">1:45am</option>
   ...
</select>


Taking the suggestion to heart, Store the adjust time as a separate attribute on the option. This way you still have access to the time selected as well as the adjusted time. You no longer have to move forward four children since both values are now accessible.

$('.startTime222').change(function() {
   adjustTime = $(".startTime option:selected").attr("data-adjust");
});

<select name="startTime" class="startTime222 required" id="startTime2" >
   <option value="00:00:00" data-adjust="01:00:00">12:00am</option>
   <option value="00:15:00" data-adjust="01:15:00">12:15am</option>
   <option value="00:30:00" data-adjust="01:30:00">12:30am</option>
   <option value="00:45:00" data-adjust="01:45:00">12:45am</option>
   <option value="01:00:00" data-adjust="02:00:00">1:00am</option>
   <option value="01:15:00" data-adjust="02:15:00">1:15am</option>
   <option value="01:30:00" data-adjust="02:30:00">1:30am</option>
   <option value="01:45:00" data-adjust="02:45:00">1:45am</option>
   ...
</select>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜