全球彩票平台_全球彩票注册平台|官网下载地址

热门关键词: 全球彩票平台,全球彩票注册平台,全球彩官网下载地址

javascript兑现全选,vue完结全选和反选作用

vue完成全选和反选成效,vue达成全选

正文实例为大家分享了vue达成全选反选成效的切实可行代码,供咱们仿照效法,具体内容如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<script type="text/javascript" src = "vue.js"></script>
<body>
    <div id = "test">
      <input type='checkbox' v-model="checkBox.checked" class='input-checkbox' @click='checkedAll'>全选
      <div v-for='checkb in checkboxData'>
        <input  type='checkbox' class='input-checkbox' @click="checkItem" v-model='checkBox.items[checkb.id]'>
        {{checkb.value}}
      </div>

    </div>

</body>
<script>
  var vue = new Vue({
    el:"#test",
    data:{
      checkboxData:[
      {
        id:'1',
        value:'苹果'
      },{
        id:'2',
        value:'荔枝'
      },{
        id:'3',
        value:'香蕉'
      },{
        id:'4',
        value:'火龙果'
      }
      ],
      checkBox:{
        checked:false,
        items:{}
      }

    },
    methods:{
      checkedAll: function() {
        var _this = this;
        console.log(_this.checkboxData);
        console.log(this.checkBox.items);
        this.checkboxData.forEach(function (item) {
          console.log(item.id);
          _this.checkBox.items[item.id] = _this.checkBox.checked;
          console.log(_this.checkBox.items);
        });
        //实现反选

      },
      checkItem:function(){
        var unchecked = 0;
        var _this = this;
        this.checkboxData.forEach(
          function(item) {
            unchecked  = (! _this.checkBox.items[item.id]) || 0;
          });
        _this.checkBox.checked = unchecked > 0 ? false : true;
      }

    }

  })
</script>

</html>

全球彩官网下载地址,以上便是本文的全体内容,希望对大家的学习抱有辅助,也期待大家多多帮助帮客之家。

本文实例为大家分享了vue达成全选反选功用的实际代码,供大家参照他事他说加以考察,具体内容如下 !DOCTYPE htmlhtml l...

正文实例为大家分享了vue达成全选反选功用的有血有肉代码,供大家参考,具体内容如下

本文实例为我们大快朵颐了vue完成单选和多选效用的实际代码,供大家参谋,具体内容如下复制代码

javascript贯彻轻易的全选和反选作用,javascript完结全选

本文实例批注了javascript完成轻巧的全选和反选功用的事无巨细代码,分享给大家供大家参照他事他说加以考察,具体内容如下

效果图:

全球彩官网下载地址 1

实际代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>全选反选</title>
</head>
<body>

  <input type="button" value="全选" id="all">
  <input type="button" value="反选" id="reverse">
  <input type="checkbox" id="flagCheck">
  <ul id="checkboxList">
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
    <li><input type="checkbox"></li>
  </ul>
  <p>
    布尔属性,只要name即可,值可为空
    checked,selected,readonly,disabled....
  </p>
  <script type="text/javascript">
  //1.找节点
  var allBtn = document.querySelectorAll("#all")[0];
  var reverseBtn = document.querySelector("#reverse");
  var flagCheck = document.getElementById("flagCheck");
  var checkList = document.querySelectorAll("#checkboxList input");
  function checkAll() {
    for(var j = 0; j < checkList.length; j  ) {
      if(!checkList[j].checked) {
        break;
      }
    }
    if(j == checkList.length) {
      // alert("全部为真")
      flagCheck.checked = true;
    }else {
      // alert("至少一个不为真");
      flagCheck.checked = false;
    }
  }
  //2.加事件
  //全选
  allBtn.onclick = function() {
    if(flagCheck.checked) {
      flagCheck.checked = false;
      for(var i = 0; i < checkList.length; i  ) {
        checkList[i].checked = false;
      }
    }else {
      flagCheck.checked = true;
      for(var i = 0; i < checkList.length; i  ) {
        checkList[i].checked = true;
      }
    }

  }
  //反选
  reverseBtn.onclick = function() {
    for(var i = 0; i < checkList.length; i  ) {
      if(checkList[i].checked) {
        checkList[i].checked = false;
      }else {
        checkList[i].checked = true;
      }
    }
    //执行检查所有checkList是否被选上了
    checkAll();
  }

  for(var i = 0; i < checkList.length; i  ) {
    checkList[i].onclick = checkAll;
  }
  </script>
</body>
</html>

梦想本文所述对大家学习javascript程序设计有着援助。

本文实例为我们享用了js复选框的全选和注销全选的实际代码,供大家参考,具体内容如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<script type="text/javascript" src = "vue.js"></script>
<body>
    <div id = "test">
      <input type='checkbox' v-model="checkBox.checked" class='input-checkbox' @click='checkedAll'>全选
      <div v-for='checkb in checkboxData'>
        <input  type='checkbox' class='input-checkbox' @click="checkItem" v-model='checkBox.items[checkb.id]'>
        {{checkb.value}}
      </div>

    </div>

</body>
<script>
  var vue = new Vue({
    el:"#test",
    data:{
      checkboxData:[
      {
        id:'1',
        value:'苹果'
      },{
        id:'2',
        value:'荔枝'
      },{
        id:'3',
        value:'香蕉'
      },{
        id:'4',
        value:'火龙果'
      }
      ],
      checkBox:{
        checked:false,
        items:{}
      }

    },
    methods:{
      checkedAll: function() {
        var _this = this;
        console.log(_this.checkboxData);
        console.log(this.checkBox.items);
        this.checkboxData.forEach(function (item) {
          console.log(item.id);
          _this.checkBox.items[item.id] = _this.checkBox.checked;
          console.log(_this.checkBox.items);
        });
        //实现反选

      },
      checkItem:function(){
        var unchecked = 0;
        var _this = this;
        this.checkboxData.forEach(
          function(item) {
            unchecked  = (! _this.checkBox.items[item.id]) || 0;
          });
        _this.checkBox.checked = unchecked > 0 ? false : true;
      }

    }

  })
</script>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta>
 <title>Document</title>
 <script src="../vue.js"></script>
 <style>
  ul, li {
   list-style-type: none;
  }

  * {
   margin: 0;
   padding: 0;
  }

  .border-1px {
   position: relative;
  }

  .border-1px:after {
   display: block;
   position: absolute;
   left: 0;
   bottom: 0;
   width: 100%;
   border-top: 1px solid rgba(7, 17, 27, .1);
   content: ' ';
  }

  @media (-webkit-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5) {
   .border-1px::after {
    -webkit-transform: scaleY(0.7);
    transform: scaleY(0.7);
   }
  }

  @media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2) {
   .border-1px ::after {
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
   }
  }

  #example {
   margin: 20px;
  }

  h3 {
   font-size: 26px;
   margin-left: 20px;
   height: 60px;
  }

  .self-radio {
   display: none;
  }

  .self-radio   label {
   -webkit-appearance: none;
   background-color: #fff;
   border: 1px solid #aaa;
   border-radius: 50px;
   display: inline-block;
   position: relative;
   width: 30px;
   height: 30px;
   box-sizing: border-box;
  }

  .self-radio:checked   label {
   border: 1px #47d9bf solid;
  }

  .self-radio:checked   label:after {
   position: absolute;
   top: 9px;
   left: 9px;
   content: ' ';
   width: 10px;
   height: 10px;
   border-radius: 50px;
   background: #47d9bf;
   box-shadow: 0px 0px 5px 0px #47d9bf;
  }

  .check-area {
   display: inline-block;
   width: 400px;
   padding: 12px 20px;
   border: 1px solid #aaa;
   border-top-left-radius: 4px;
   border-top-right-radius: 4px;
  }

  li {
   height: 60px;
  }

  li .self-radio   label {
   vertical-align: middle;
  }

  li span {
   margin-left: 20px;
   display: inline-block;
   line-height: 60px;
   font-size: 22px;
  }

  p {
   height: 60px;
   line-height: 60px;
   margin-left: 20px;
  }

  p span {
   color: #f00;
  }

  .btn {
   margin: 20px auto;
   width: 100%;
   text-align: center;
  }

  .btn button {
   width: 120px;
   height: 40px;
   line-height: 30px;
   font-size: 16px;
   color: #fff;
   background: #47d9bf;
   border: 1px #23d5b6 solid;
   border-radius: 6px;
   text-align: center;
   outline: none;
  }

  .btn button:hover {
   background: #23d5b6;
  }
 </style>
</head>

<body>
<div id="example">
 <h3>单选按钮</h3>
 <div class="check-area" v-show="items.length!=0">
  <ul>
   <li class="border-1px" v-for="(item,index) in items">
    <input class="self-radio" type="radio"
      :id="'radio-' item.id"
      :data-id="'food-' item.id" name="radio"
      :checked="index==0"
      :value="item.value"
      v-model="checkValue">
    <label :for="'radio-' item.id" @click="setCheckValue(item)"></label>
    {{item.value}}
   </li>
  </ul>
  <p>您选择了:{{checkValue}}</p>
  <div class="btn">
   <button @click="showCheck(checkId)">按钮</button>
   {{checkId}}
  </div>
 </div>
</div>
<script>
 var itemData = [{id: '20170811001', value: '香蕉'},
  {id: '20170811002', value: '苹果'},
  {
   id: '20170811003',
   value: '梨子'
  }, {id: '20170811004', value: '葡萄'}]
 //itemData = [];
 var vm = new Vue({
  el: '#example',
  data: {
   items: '',
   checkValue: '',
   checkId: ''
  },
  methods: {
   init: function () {

   },
   initData: function () {
    var self = this;
    self.items = itemData;
    if (itemData.length != 0) {
     self.checkValue = self.items[0].value;
     self.checkId = 'food-'   self.items[0].id
    }
   },
   setCheckValue: function (item) {
    this.checkId = 'food-'   item.id;
   }
   ,
   showCheck: function () {
    console.log(this.checkId)
   }
  },
  mounted: function () {
   this.initData();
  }
 })

</script>
</body>

</html>

你大概感兴趣的小说:

  • 兼容ie和firefox版本的js反选 全选 多选框
  • javaScript checkbox 全选/反选及批量刨除
  • javascript 全选/反选,撤销选用效果
  • Jquery CheckBox全选方法代码附js checkbox全选反选代码
  • js 分页全选或反选标志达成代码
  • js操作CheckBoxList完成全选/反选(在客服端实现)
  • jquery全选/全不选/反选另一种完毕情势(合作原生js)
  • js达成checkbox全选和反选示例

本文实例批注了javascript实现轻巧的全选和反选功用的详尽代码,分享给大家供我们参...

效果图:

本文由全球彩票平台发布于全球彩官网下载地址Web前端,转载请注明出处:javascript兑现全选,vue完结全选和反选作用

TAG标签: 全球彩票平台
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。