目标单个复选框值



>我有一个包含 3 个值的复选框"父亲"、"母亲"和秘书。我尝试定位单个复选框值,但问题是我不知道标签的 ID/名称。我不能使用 getElementById , getElementByClass 等...

我尝试添加一个特定的 CSS 类"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"]');

最新更新