当前位置: 移动技术网 > IT编程>开发语言>Jquery > Jquery实现点击当前radio button设置选中属性,其它设置非选中属性

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

2020年01月10日  | 移动技术网IT编程  | 我要评论

一、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)
        })
      })
    });

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网