简体   繁体   English

使用复选框名称选择/取消选择复选框

[英]select/unselect check boxes using checkbox name

I have check boxes in the table created dynamically using JSF and i get the HTML output like the following, 我在使用JSF动态创建的表中有复选框,并且得到如下所示的HTML输出,

 <input name="testForm:j_idt78:0:negative" id="testForm:j_idt78:0:negative" onchange='PrimeFaces.ab({s:this,e:"change",p:"testForm:j_idt78:0:negative"});' type="checkbox">
<input name="testForm:j_idt78:0:positive" id="testForm:j_idt78:0:positive" onchange='PrimeFaces.ab({s:this,e:"change",p:"testForm:j_idt78:0:positive"});' type="checkbox">
<input name="testForm:j_idt78:0:na" id="testForm:j_idt78:0:na" onchange='PrimeFaces.ab({s:this,e:"change",p:"testForm:j_idt78:0:na"});' type="checkbox">

i get the following exception at the console : SCRIPT5022: Syntax error, unrecognized expression: unsupported pseudo: j_idt78 我在控制台上收到以下异常: SCRIPT5022: Syntax error, unrecognized expression: unsupported pseudo: j_idt78

how do i select the checkbox based on the name attribute? 如何根据名称属性选择复选框?

You'd use the CSS attribute selector : 您将使用CSS属性选择器

 const inputId = 'testForm:j_idt78:0' const negativeId = inputId + ':negative' document.querySelector('input[type="checkbox"][name="' + negativeId + '"]').checked = true 
 <input name="testForm:j_idt78:0:negative" id="testForm:j_idt78:0:negative" type="checkbox"> <input name="testForm:j_idt78:0:positive" id="testForm:j_idt78:0:positive" type="checkbox"> <input name="testForm:j_idt78:0:na" id="testForm:j_idt78:0:na" type="checkbox"> 

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

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