Jquery實現點擊當前radio button設置選中屬性,其它設置非選中屬性

1、HTML代碼:spa

<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>

2、jQuery代碼:code

$('.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)
        })
      })
    });
相關文章
相關標籤/搜索