单击时隐藏和显示复选框,标签和父<p>标签

时间:2019-11-13 17:13:12

标签: jquery

我需要隐藏p标签,但是我不能更改HTML,因此我尝试使用jQuery处理元素。我可以隐藏复选框和标签,但无法折叠P标签,从而留下空白。使用控件复选框,如何折叠隐藏组的父p标签以折叠间隙?

谢谢!

jQuery

<script type="text/javascript">

        $(function () {
        $('#list_31660').change(function () { // listener
        $("#list_31420").toggle(this.checked); // action
        $("label[for='list_31420']").toggle(this.checked);
        $("#list_31656").toggle(this.checked); // action
        $("label[for='list_31656']").toggle(this.checked);

    }).change();
});
    </script>   

HTML

<form accept-charset="UTF-8" method="post" action="">
  <p class="form-field email-pref pd-checkbox     %%form-field-dependency-css%%">
    <input type="checkbox" name="list[]" id="list_31660" value="31660" />
    &nbsp;
    <label class="inline" for="list_31660">Control Checkbox</label>
  </p>

  <p class="form-field email-pref pd-checkbox     %%form-field-dependency-css%%">
    <input type="checkbox" name="list[]" id="list_31656" value="31656" />
       &nbsp;
    <label class="inline" for="list_31656">Hide Show 1</label>
  </p>

  <p class="form-field email-pref pd-checkbox     %%form-field-dependency-css%%">
    <input type="checkbox" name="list[]" id="list_31420" value="31420"  />
    &nbsp;
    <label class="inline" for="list_31420">Hide Show 2</label>
  </p>

  <p class="form-field email-pref pd-checkbox     %%form-field-dependency-css%%">
    <input type="checkbox" name="list[]" id="list_31662" value="31662" />
    &nbsp;
    <label class="inline" for="list_31662">Another Option</label>
  </p>

</form>

1 个答案:

答案 0 :(得分:1)

您需要定位create table so_case_cols ( SSN varchar2(11), "ssn" varchar2(11), "ssN" varchar2(11)); select * from user_tab_cols where upper(column_name) like '%SSN%'; ,而不是隐藏checkboxlabel。您可以使用p函数或.parent()。在这种情况下,使用.closest('p')更好,但是.parent的用途更多。试试这个:

.closest

文档:

https://api.jquery.com/parent/#parent-selector

https://api.jquery.com/closest/#closest-selector