多选框checkbox实现单选效果

需要把一组多选框实现单选的效果功能。使用jQuery只需几行代码就能搞定。这里记录备忘。

1
2
3
4
5
6
$("input[name='task_id']").click(function(){
    if($(this).prop('checked')){
        $("input[name='task_id']").prop('checked',false);
        $(this).prop('checked',true);
    }
});