Jquery实现点击当前radio button设置选中属性,其它设置非选中属性

一、HTML代码:

<div class="ques-tc-r" id="question_type">
                          <ul class="clearfix">
                            <li class="select-cur">
                              <input type="radio" value="1" name="question_type" checked="checked" />
                              <span>问题A</span>
                            </li>
                            <li>
                              <input type="radio" value="2" name="question_type" />
                              <span>问题B</span>
                            </li>
                            <li>
                              <input type="radio" value="3" name="question_type" />
                              <span>问题C</span>
                            </li>
                            <li>
                              <input type="radio" value="4" name="question_type" />
                              <span>问题D</span>
                            </li>
                          </ul>
                        </div>

二、jQuery代码:

$('.ques-tc-r ul li').each(function (i, o) {
      $(o).click(function () {
        $(o).addClass('select-cur');
        $(o).siblings().removeClass('select-cur');
        $('.select-cur > input').attr('checked', true)
        $('.ques-tc-r ul li:not(.select-cur) > input').each(function (index, it) {
          $(it).attr("checked", false)
        })
      })
    });

猜你喜欢

转载自www.cnblogs.com/phperlinxinlan/p/12173067.html