【发布时间】:2014-03-27 09:31:25
【问题描述】:
我正在制作一种幻灯片形式,当用户单击下一张图片时,还必须选择单选按钮。我得到了滑动工作,“下一个按钮”也在工作,但我有点卡在“上一个”按钮上。不明白为什么它不起作用。
(fiddle)
这是我目前得到的,HTML:
<form>
<div>
<div class="button prev"><</div>
<ul>
<li>
<input type="radio" id="choise_1" name="first_choise" checked="checked"/>
<label for="choise_1">One</label>
</li>
<li>
<input type="radio" id="choise_2" name="first_choise"/>
<label for="choise_2">Two</label>
</li>
<li>
<input type="radio" id="choise_3" name="first_choise"/>
<label for="choise_3">Three</label>
</li>
</ul>
<div class="button next">></div>
</div>
<div>
<div class="button prev"><</div>
<ul>
<li>
<input type="radio" id="choise_1" name="second_choise" checked="checked"/>
<label for="choise_1">One</label>
</li>
<li>
<input type="radio" id="choise_2" name="second_choise"/>
<label for="choise_2">Two</label>
</li>
<li>
<input type="radio" id="choise_3" name="second_choise"/>
<label for="choise_3">Three</label>
</li>
</ul>
<div class="button next">></div>
</div></form>
jQuery:
$(document).ready(function(){
$('.prev').click(function(){
$(this).next().find('input:checked').parent().prev().children('input').attr("checked", true);
$(this).next().find('input:checked').last().removeAttr("checked");
});
$('.next').click(function(){
$(this).prev().find('input:checked').parent().next().children('input').attr("checked", true);
$(this).prev().find('input:checked').eq(0).parent().prev().children('input').removeAttr("checked");
});});
【问题讨论】:
-
你创建了小提琴工作,现在你的问题是什么?
标签: jquery html radio-button