5.17批量修改样式,全选反选不选

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            *{
            margin:0 auto;
            padding: 0;
        }
        .btn{
            width: 200px;
            height: 60px;
            background-color: #002752;
            color:white;
            text-align: center;
            line-height:60px;
            border-radius: 5px;
        }
        .list{
            width:400px;
            height: 200px;
            border: 1px solid #002752;
            margin-top: 20px;
        }
        </style>

    </head>
    <body>
        <input type="text" name="" id="" value="" />
        <input type="text" name="" id="" value="" />
        <div class="btn">批量修改样式</div>
        <div class="list"></div>
        <div class="list"></div>
        <div class="list"></div>

        <div class="btn"bs="1">全选</div>
        <div class="btn"bs="2">反选</div>
        <div class="btn"bs="3">不选</div>

        <input type="checkbox" name="" id="" value="" />租房
        <input type="checkbox" name="" id="" value="" />买房
        <input type="checkbox" name="" id="" value="" />卖房
        <input type="checkbox" name="" id="" value="" />中介
        <input type="checkbox" name="" id="" value="" />商家

    </body>
</html>
<script type="text/javascript">
     var btnlist =document.getElementsByClassName("btn");
     for(var i=1;i<btnlist.length;i++){
         btnlist[i].onclick=function () {
             //this关键词
             //this 跟点击,移入,移出事件在一起用;
             //console.log(this);
             // var ipt =document.getElementsByTagName("input");
             var ipt=document.querySelectorAll("input[type=checkbox]");
             switch(this.getAttribute("bs")){
                 case "1":
                 for(var i=0;i<ipt.length;i++){
                     ipt[i].checked=true;
                 }
                 break;
                 case "2":
                 for(var i=0;i<ipt.length;i++){
                     ipt[i].checked=ipt[i].checked?false:true;
                 }
                 break;
                 default:
                        var num=0;
                        while (num<ipt.length){
                               ipt[num].checked=false;
                               num++;
                        }
                        break;
             }
         }
     }
     //1.找到需要挂事件的元素
     var btn = document.getElementsByClassName("btn")[0];
     //2.挂事件
     btn.onclick = function(){
         //3找到要修改的元素
         var list = document.getElementsByClassName("list");
         //4 循环元素,给每一个改变class名字
         for(var i=0;i<list.length;i++){
            list[i].style.width="300px";
            list[i].style.height="300px";
            list[i].style.backgroundColor="#003B4D";
         }
     }

原文地址:https://www.cnblogs.com/sunhao1987/p/9052811.html

时间: 2024-08-23 11:16:34

5.17批量修改样式,全选反选不选的相关文章

批量修改样式及全选反选

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin:0 auto; padding: 0; } .btn{ width: 200px; height: 60px; background-color: #002752; color:w

使用word中的宏实现选中指定类型表格,并且批量修改样式结构

使用word中的宏实现选中指定类型表格,并且批量修改样式结构 Sub SelectAllTables() ' ' SelectAllTables 宏 选中所有表格 ' ' Dim tempTable As Table Application.ScreenUpdating = False '判断文档是否被保护 If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then MsgBox "文档已保护,此时不能选中多个表格!" E

checkbox全选 反选 不选 并获取id的值

$("#lblContents :checkbox").each(function () {                 if (this.checked) {                     this.checked = false;                     ids ="";                 }                 else {                     this.checked = true;

input -多选 反选 不选

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div{ width: 1000px; height: 200px; background-color: lavender; box-shadow: 5px 5px 2px lightblue; }

js制作全选 反选 不选

<!DOCTYPE html><html >    <head>        <meta charset="utf-8">        <title></title>    </head>    <style>        </style>        <script>    window.onload=function (){        var aBtn

复选框 全选 反选 不选

<script language="javascript"> var put=document.all.tags("input"); //全选function selall(){for (i=0;i<put.length;i++){   if (put[i].type=="checkbox")    put[i].checked=true;}} //不选function Nselall(){for (i=0;i<put.l

cssText批量修改样式

cssText所有浏览器都支持. cssText 的使用 obj.style.cssText = " width:200px;position:absolute;left:100px;"; 正如那篇文章所提cssText会清除之前元素含有的样式,所以得使用 obj.style.cssText += " width:200px;position:absolute;left:100px;"; 但是在IE中的最后一个分号会被删除 obj.style.cssText +=

jquery 全选 反选 取消 批量删除

首选引入jquery 全选 //全选 function myall(){ $("input[name='d[]']").each(function(index,e){ $(this).prop('checked',true); }); } 取消 //当true改为false时为取消 // function no(){ // $("input[name='d[]']").each(function(index,e){ // $(this).prop('checked'

jQuery实现全选/反选和批量删除

//全选/全不选 $(function(){ //初始化时候,删除按钮隐藏 $("input[name='Delete'").css("display",'none'); $("#CheckAll").bind("click",function(){ $("input[name='Check[]']").prop("checked",this.checked); //显示删除按钮 if(