欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于jQuery實(shí)現(xiàn)復(fù)選框的全選 全不選 反選功能

 更新時(shí)間:2014年11月24日 14:49:52   投稿:hebedich  
本文分享一段基于jQuery實(shí)現(xiàn)的復(fù)選框全選、全不選、反選功能的代碼,有需要的小伙伴直接帶走吧

本代碼是在眾多的jQuery復(fù)選框功能代碼中精選出來的,本人項(xiàng)目中使用的代碼,這里分享給大家。

jQuery代碼:

復(fù)制代碼 代碼如下:

        $(function(){
            $("#checkedAll").click(function(){
                $('[name=items]:checkbox').attr('checked',true);
            });
            $("#checkedNo").click(function(){
                $('[name=items]:checkbox').attr('checked',false);
            });
            $("#checkedRev").click(function(){
                $('[name=items]:checkbox').each(function(){
                    //$(this).attr('checked',!$(this).attr('checked'));
                    this.checked = !this.checked;
                });
            });
            $("#send").click(function(){
               var str = "你選中的是:\r\n";
               $('[name=items]:checkbox:checked').each(function(){
                   str += $(this).val()+"\r\n";
               });
                alert(str);
            });
        }); 

HTML代碼:

復(fù)制代碼 代碼如下:

    你愛好的運(yùn)動是?<br>
    <input type="checkbox" name="items" value="足球"/>足球
    <input type="checkbox" name="items" value="籃球"/>籃球
    <input type="checkbox" name="items" value="羽毛球"/>羽毛球
    <input type="checkbox" name="items" value="乒乓球"/>乒乓球<br>
    <input type="button" id="checkedAll" value="全 選"/>
    <input type="button" id="checkedNo" value="全不選"/>
    <input type="button" id="checkedRev" value="反 選"/>
    <input type="button" id="send" value="提 交"/>

小伙伴們使用起來是不是很方便,這也是本人千挑萬選出來的,希望能對大家有所幫助。

相關(guān)文章

最新評論