layui 单选框取消选中

<ul>
                                                                <li>
                                            <span class="time">17:18</span>
                                            <span class="type">内勤</span>
                                            <span class="address" dataid="1535562000194261055">广东省广州市天河区五山路靠近金山大厦(五山路)</span>
                                            <input data-check="false" lay-filter="jiedian" id="1" type="radio" name="companyName" value="广东省广州市天河区五山路靠近金山大厦(五山路)">
                                            <label for="1"></label>
                                        </li>
                                        <li>
                                            <span class="time">13:08</span>
                                            <span class="type">内勤</span>
                                            <span class="address" dataid="1535562000194264261">广东省广州市天河区翰景路250号靠近广州天河软件金山园区</span>
                                            <input data-check="false" lay-filter="jiedian" id="2" type="radio" name="companyName" value="广东省广州市天河区翰景路250号靠近广州天河软件金山园区">
                                            <label for="2"></label>
                                        </li>
                                        
                                    
                                    

                    </ul>

关键代码
$(this).prop('checked', false);
layui.form.render();
用自定义属性 data-check来判读是第是否第二次点击


        // 再次点击取消选中
  
        $('.t-body input').on('click',function () {
           var xuanzhong = $(this).attr('data-check');
           if(xuanzhong == "false"){
                $('.t-body input').each(function (i, input) {
                   $(input).attr('data-check', "false");
               })
               $(this).attr('data-check', "true");
                $(this).prop('checked', true);
               layui.form.render(); 
           } else{
               $('.t-body input').each(function (i,input) {
                   $(input).attr('data-check', "false");
               })
                $(this).prop('checked', false);
               layui.form.render(); 
           }

        })

posted @ 2018-09-03 11:26  山村码农  阅读(9670)  评论(0编辑  收藏  举报