将checkbox设置成单选

jquery-1.5.2.js以上版本
<script type="text/javascript">
    $(function(){
        $(':checkbox[name=cb]').each(function(){
            $(this).click(function(){
                if($(this).attr('checked')){
                    $(':checkbox[name=cb]').removeAttr('checked');
                    $(this).attr('checked','checked');
                }
            });
        });
    });
  </script>


<input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>
  <input type="checkbox" name="cb"/>

  

posted @ 2012-11-18 17:55  程序员-初学者  阅读(866)  评论(0编辑  收藏  举报