我正在尝试向单选样式导航添加“下一个”和“上一个”按钮。
HTML
<div class="month-picker">
<button type="buton" class="month-picker-nav" onclick="dayNavigation('prev');"><</button>
<fieldset class="month-picker-fieldset">
<input type="radio" name="month" value="day1" id="day1" checked="checked">
<label for="day1" class="month-picker-label">Day 1</label>
<input type="radio" name="month" value="day2" id="day2">
<label for="day2" class="month-picker-label">Day 2</label>
<input type="radio" name="month" value="day3" id="day3">
<label for="day3" class="month-picker-label">Day 3</label>
<input type="radio" name="month" value="day4" id="day4">
<label for="day4" class="month-picker-label">Day 4</label>
<input type="radio" name="month" value="day5" id="day5">
<label for="day5" class="month-picker-label">Day 5</label>
<input type="radio" name="month" value="day6" id="day6">
<label for="day6" class="month-picker-label">Day 6</label>
</fieldset>
<button type="buton" class="month-picker-nav" onclick="dayNavigation('next');">></button>
</div>
JAVASCRIPT:
dayNavigation = function (direction) {
var all = $('.month-picker-fieldset input:radio');
var current = $('.month-picker-fieldset input:radio:checked');
var index;
if (direction == 'prev') {
index = all.index(current) - 1;
} else {
index = all.index(current) + 1;
}
all.eq(index).attr('checked', 'checked');
return false;
};
Fiddle: http://jsfiddle.net/hTgv3/5/
我的问题是前一个按钮无法正常工作,并且一旦手动选择或“点击”被调用,下一个按钮就不再起作用。