Answers:
您可以这样使用querySelectorAll()
:
var test = document.querySelectorAll('input[value][type="checkbox"]:not([value=""])');
转换为:
获取所有具有属性“值”且属性“值”不为空的输入。
在此演示中,它禁用具有非空白值的复选框。
[type="checkbox"]
。更新了我的答案。
以您的示例为例:
<input type="checkbox" id="c2" name="c2" value="DE039230952"/>
在示例中,将$$替换为document.querySelectorAll:
$$('input') //Every input
$$('[id]') //Every element with id
$$('[id="c2"]') //Every element with id="c2"
$$('input,[id]') //Every input + every element with id
$$('input[id]') //Every input including id
$$('input[id="c2"]') //Every input including id="c2"
$$('input#c2') //Every input including id="c2" (same as above)
$$('input#c2[value="DE039230952"]') //Every input including id="c2" and value="DE039230952"
$$('input#c2[value^="DE039"]') //Every input including id="c2" and value has content starting with DE039
$$('input#c2[value$="0952"]') //Every input including id="c2" and value has content ending with 0952
$$('input#c2[value*="39230"]') //Every input including id="c2" and value has content including 39230
将示例直接用于:
const $$ = document.querySelectorAll.bind(document);
一些补充:
$$(.) //The same as $([class])
$$(div > input) //div is parent tag to input
document.querySelector() //equals to $$()[0] or $()
values=""