不要问 为什么不直接用radio,问就是客户要求。

下列代码中searchForm,指的是所有checkbox的父级容器。

          searchForm.find('input[type="checkbox"]').click(function (evt) {
                if(evt.target.checked === true){
                    searchForm.find('input[type="checkbox"]').each(function () {
               //所有value与当前checkbox不匹配的,全部置为false
                        if(this.value !== evt.target.value){
                            this.checked = false;
                        }
                    });
                    //TODO: sth.
                }
            });

 

jQuery设置checkbox单选

 

相关文章: