Home > Web Front-end > JS Tutorial > body text

基于jQuery实现复选框的全选 全不选 反选功能_jquery

WBOY
Release: 2016-05-16 16:30:31
Original
1396 people have browsed it

本代码是在众多的jQuery复选框功能代码中精选出来的,本人项目中使用的代码,这里分享给大家。

jQuery代码:

复制代码 代码如下:

        $(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 = "你选中的是: \n";
               $('[name=items]:checkbox:checked').each(function(){
                   str += $(this).val()+"\r\n";
               });
                alert(str);
            });
        }); 

HTML代码:

复制代码 代码如下:

    你爱好的运动是?

    足球
    篮球
    羽毛球
    乒乓球

   
   
   
   

小伙伴们使用起来是不是很方便,这也是本人千挑万选出来的,希望能对大家有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!