Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何隐藏';在ACF的一个灵活的内容框中,但不隐藏其他内容_Jquery_Wordpress_Advanced Custom Fields_Gutenberg Blocks - Fatal编程技术网

Jquery 如何隐藏';在ACF的一个灵活的内容框中,但不隐藏其他内容

Jquery 如何隐藏';在ACF的一个灵活的内容框中,但不隐藏其他内容,jquery,wordpress,advanced-custom-fields,gutenberg-blocks,Jquery,Wordpress,Advanced Custom Fields,Gutenberg Blocks,我在我的区块上使用灵活的内容将图像添加到帖子中。在这个灵活的内容中,我有一个复选框,可以使该图像成为功能图像。我想知道是否有一种方法,如果在第一个灵活的内容中选中一个复选框,它会在其余的内容中隐藏该复选框。问题是它们都有相同的类(.acf-field-5f8cf27f39a66)和ID(#三个img加上功能img),所以当您隐藏该复选框时,它会隐藏所有这些内容。任何关于如何解决这个问题的解决方案。谢谢 到目前为止,我掌握的代码是: $(document).on("click"

我在我的区块上使用灵活的内容将图像添加到帖子中。在这个灵活的内容中,我有一个复选框,可以使该图像成为功能图像。我想知道是否有一种方法,如果在第一个灵活的内容中选中一个复选框,它会在其余的内容中隐藏该复选框。问题是它们都有相同的类(
.acf-field-5f8cf27f39a66
)和ID(
#三个img加上功能img
),所以当您隐藏该复选框时,它会隐藏所有这些内容。任何关于如何解决这个问题的解决方案。谢谢

到目前为止,我掌握的代码是:

$(document).on("click", "#three_img_plus_feature_img input", function () {
    if ($("#three_img_plus_feature_img input").is(":checked")) {
        $("#three_img_plus_feature_img label").css("display", "none");
    } else {
        $("#three_img_plus_feature_img label").css("display", "block");
    }
});
HTML如下所示。添加的每个项目都是相同的,因此如果有两个项目,它们看起来都一样

<div id="three_img_plus_feature_img" class="acf-field acf-field-checkbox acf-field-5f8cf27f39a66" data-name="three_img_plus_feature_img" data-type="checkbox" data-key="field_5f8cf27f39a66" data-conditions="[[{&quot;field&quot;:&quot;field_5f8cf27f39951&quot;,&quot;operator&quot;:&quot;!=empty&quot;}]]">
  <div class="acf-label"></div>
  <div class="acf-input">
      <input type="hidden" name="acf-block_6019b745d990c[field_5f8cf27e7c782 [6019b7a4d990e][field_5f8cf27f39a66]">
      <ul class="acf-checkbox-list acf-bl">
          <li><label class=""><input type="checkbox" id="acf-block_6019b745d990c-field_5f8cf27e7c782-6019b7a4d990e-field_5f8cf27f39a66-three_img_plus_set_feature_img" name="acf-block_6019b745d990c[field_5f8cf27e7c782][6019b7a4d990e][field_5f8cf27f39a66][]" value="three_img_plus_set_feature_img"> Set featured image</label></li>
      </ul>
  </div>

  • 设置特色图像

您可以在单击的类上添加一个临时类,用于标识。也许这不是最好的方法,但它可以起作用:

$(文档)。在(“单击“,”三个img加上\u功能\u img输入“,函数(){
$(“#三个img#加上#feature#img”).removeClass('current');
$(this).closest(“#三个img#加上#feature#img”).addClass('current');
如果($(this).is(“:checked”)){
$(“#三个#img#加上(功能)img:not(.current)label”).css(“display”,“none”);
}否则{
$(“#三个#img#加上(功能)img:not(.current)label”).css(“显示”、“块”);
}
});

这很好,但是当您取消选中它时,它不会删除
.current
类。因此,当您单击复选框时,它将添加
.current
类,但当您取消选中它时,
.current
类将保留。
.current
不用于识别选中的输入,而是用于识别上次单击的输入。感谢帮助。我将以此为出发点。