目标单个复选框值
target individual checkbox value
我有一个包含 3 个值的复选框
'Father' , 'Mother' 和秘书。我试图针对单个复选框值,但问题是我不知道标签的 ID/name。
我不能使用 getElementById 、 getElementByClass 等...
我试图添加特定的 CSS class 'SPECIFIC_CSS' 但 gforms 将其添加到 li 标签中。我只能确定复选框的值(父亲、母亲、秘书)。
如何定位那些特定的复选框?我可以针对他们的价值观吗?如何?你还有其他我没有想到的方法吗?
<li id="field_31_3-1-1" class="gfield SPECIFIC_CSS field_sublabel_below field_description_below gfield_visibility_visible gf_repeater_child_field" data-repeater-parentid="1" data-repeater-repeatid="1" data-repeater-childid="1">
<label class="gfield_label">Checkboxes Test 1</label><div class="ginput_container ginput_container_checkbox"><ul class="gfield_checkbox" id="input_31_3">
<li class="gchoice_31_3_1">
<input name="input_3.1-1-1" value="Father" id="choice_31_3_1-1-1" tabindex="1" data-repeater-inputid="1" type="checkbox">
<label for="choice_31_3_1-1-1" id="label_31_3_1">Father</label></li>
<li class="gchoice_31_3_2">
<input name="input_3.2-1-1" value="Mother" id="choice_31_3_2-1-1" tabindex="1" data-repeater-inputid="2" type="checkbox">
<label for="choice_31_3_2-1-1" id="label_31_3_2">Mother</label></li>
<li class="gchoice_31_3_3">
<input name="input_3.3-1-1" value="Secretary" id="choice_31_3_3-1-1" tabindex="1" data-repeater-inputid="3" type="checkbox">
<label for="choice_31_3_3-1-1" id="label_31_3_3">Secretary</label>
</li></ul></div></li>
您可以使用如下内容:
document.querySelector('input[value="Father"]').checked = true;
或者如果您只是想要元素而不检查它:
document.querySelector('input[value="Father"]');
我有一个包含 3 个值的复选框 'Father' , 'Mother' 和秘书。我试图针对单个复选框值,但问题是我不知道标签的 ID/name。 我不能使用 getElementById 、 getElementByClass 等...
我试图添加特定的 CSS class 'SPECIFIC_CSS' 但 gforms 将其添加到 li 标签中。我只能确定复选框的值(父亲、母亲、秘书)。
如何定位那些特定的复选框?我可以针对他们的价值观吗?如何?你还有其他我没有想到的方法吗?
<li id="field_31_3-1-1" class="gfield SPECIFIC_CSS field_sublabel_below field_description_below gfield_visibility_visible gf_repeater_child_field" data-repeater-parentid="1" data-repeater-repeatid="1" data-repeater-childid="1">
<label class="gfield_label">Checkboxes Test 1</label><div class="ginput_container ginput_container_checkbox"><ul class="gfield_checkbox" id="input_31_3">
<li class="gchoice_31_3_1">
<input name="input_3.1-1-1" value="Father" id="choice_31_3_1-1-1" tabindex="1" data-repeater-inputid="1" type="checkbox">
<label for="choice_31_3_1-1-1" id="label_31_3_1">Father</label></li>
<li class="gchoice_31_3_2">
<input name="input_3.2-1-1" value="Mother" id="choice_31_3_2-1-1" tabindex="1" data-repeater-inputid="2" type="checkbox">
<label for="choice_31_3_2-1-1" id="label_31_3_2">Mother</label></li>
<li class="gchoice_31_3_3">
<input name="input_3.3-1-1" value="Secretary" id="choice_31_3_3-1-1" tabindex="1" data-repeater-inputid="3" type="checkbox">
<label for="choice_31_3_3-1-1" id="label_31_3_3">Secretary</label>
</li></ul></div></li>
您可以使用如下内容:
document.querySelector('input[value="Father"]').checked = true;
或者如果您只是想要元素而不检查它:
document.querySelector('input[value="Father"]');