css选择器 + 的使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        html,body{
            margin: 0;
        }
        *{
            margin: 0;
            padding: 0;
        }
        .inbox{
            margin: 50px auto;
            width: 400px;
            border: 1px solid gainsboro;
            border-radius: 5px;
            box-shadow: 5px 5px 5px gainsboro;
        }
        .inbox .item{
            text-align: center;
            border-bottom: 1px solid gainsboro;
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .inbox .item input{
            height: 15px;
            flex: 1;
            outline-style: none;
        }
        .inbox p {
            box-sizing: border-box;
            border-left: 1px solid gainsboro;
            flex: 5;
            text-align: left;
            padding-left: 10px;
            padding-top:10px;
            padding-bottom: 10px;
            word-break: break-all;
        }
        .inbox .item:last-child{
            border-radius: 5px;
        }
        .inbox .item:nth-child(odd){
            border-color: ghostwhite;
        }
        .inbox .item input:checked + p{
           background-color: gainsboro;
            text-decoration: line-through;
        }
    </style>
</head>
<body>
  <div class="inbox">
      <div class="item">
          <input type="checkbox">
          <p>we are not a animals</p>
      </div>
      <div class="item">
          <input type="checkbox">
          <p>we are not a animals ksljdflkajsdfkjsdfsdfsalkdjfklajldfjkljsdfadfsdfadfsaaaaaaaaaffffffffffffff</p>
      </div>
      <div class="item">
          <input type="checkbox">
          <p>we are not a animals</p>
      </div>
      <div class="item">
          <input type="checkbox">
          <p>we are not a animals</p>
      </div>
      <div class="item">
          <input type="checkbox">
          <p>we are not a animals</p>
      </div>
  </div>
</body>
<script type="application/javascript">
    const checkboxs = document.querySelectorAll('.inbox input[type="checkbox"]');
    let lastChecked;
    function handler(e){
        let isBetween = false;
        let self = this;
        if(e.shiftKey &&  this.checked){
            checkboxs.forEach(function(checkbox){
                if(checkbox ===self || checkbox ===lastChecked){//两次进入
                    console.log(checkbox);
                   isBetween = !isBetween;
                }
                if(isBetween){
                    checkbox.checked = true;
                }
            });
        }
        lastChecked = this;
    };
    checkboxs.forEach(function(checkbox){
        checkbox.addEventListener('click',handler,false)
    });
</script>
</html>

转载于:https://my.oschina.net/u/3198493/blog/1143161

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值