As shown in the picture, I want to automatically select all after single selection. How to achieve this?
Writing like this can be achieved, but every time I change this global variable, I always feel that it is a trap. Is there any good way to solve it?
forEach
这个方法是没办法提前退出的。只能用for
LoopFor logic like yours, you can update the view first
map
一下返回符合勾选条件的数组,在forEach
Use some or every for early exit, and what is the relationship between your function description and early exit
There is no way,
@crp205’s answer is correct.
some
will interrupt the loop if it returnstrue
, andevery
returnsfalse
Just terminate the loop.some
如果返回true
就会中断循环,every
有一项返回false
就终止循环.数组的遍历只有这两个支持跳出循环了,否则就得用
for
Only these two support for array traversal to break out of the loop, otherwise you have to usefor
Change forEach to every, then return false
Why doesn’t js have this syntax:
document.getElementsByxxx.checked(true/false)
means to get the number of checked or unchecked checkboxes/radios in the same category.