简体   繁体   English

如果选中了一定数量的框,如何显示图像

[英]How do I get an image to display if a certain number of boxes are checked

在此处输入图像描述

This is my current code, and I can't figure out how to change the image depending on whether the number of boxes selected is greater than or less then 3.这是我当前的代码,我不知道如何根据所选框的数量是否大于或小于 3 来更改图像。

在此处输入图像描述

You could write a little function (see below) which is fired everytime a checkbox checked value changes.您可以编写一点 function (见下文),每次复选框选中值更改时都会触发它。

let count = 0;
Document.QuerySelectorAll('[name="ckb"]').forEach(function (ckb)
   {
      if (ckb.checked)
         count ++;
   });
if(count >= 3)
      Document.QuerySelector('Image').classList.Remove('hidden');
else
      Document.QuerySelector('Image').classList.Add('hidden');

   

The hidden class should be added in your css and to the Image you want to hide.隐藏的 class 应添加到 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 和要隐藏的图像中。 It could look like this:它可能看起来像这样:

.hidden {
   opacity = 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM