我想通过javascript复选框。通过javascript控制台打钩复选框标签名
事情是我有一个任务来检查更多的300个复选框与特定的名称。
我可以检查一个框,或检查所有框......但如何检查特定的框?
下面是一个例子:
<li id="s1" class="city-select">
<input name="rid" id="r1" value="1" type="checkbox">
<label for="r1" id="l1">Paris</label>
</li>
<li id="s1" class="city-select">
<input name="rid" id="r2" value="2" type="checkbox">
<label for="r2" id="l2">Plovdiv</label>
</li>
<li id="s1" class="city-select">
<input name="rid" id="r3" value="3" type="checkbox">
<label for="r3" id="l3">Berlin</label>
</li>
我想只打勾“柏林”和“巴黎” - 这里是我用打勾的所有东西:
[].forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(el){el.checked=true});
这里我试图键入:
$("lable:contains('paris, berlin')").prev().find('input').addAttr("checked");
'$(“。city- ('berlin')“)。prev('input')。prop(”checked“,true);' –