Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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 如果aria已展开=";true更改其他元素样式_Jquery_Html_Css_Bootstrap 4 - Fatal编程技术网

Jquery 如果aria已展开=";true更改其他元素样式

Jquery 如果aria已展开=";true更改其他元素样式,jquery,html,css,bootstrap-4,Jquery,Html,Css,Bootstrap 4,在引导折叠内容中,当a[aria expanded=“true]”为true时,我尝试更改.pannel标题背景 也可以在这里再添加一个标记,这样不会影响它们的折叠吗 这是HTML <div class="panel panel-default"> <div class="panel-heading"> <div class="panel-title"> <h4>title </h4>

在引导折叠内容中,当
a[aria expanded=“true]”
为true时,我尝试更改
.pannel标题
背景

也可以在这里再添加一个
标记,这样不会影响它们的折叠吗

这是HTML

  <div class="panel panel-default">
    <div class="panel-heading">
      <div class="panel-title">
        <h4>title </h4>
        <button class="button">Sign up</button>
        <a data-toggle="collapse" data-parent="#accordion" href="#" class="" aria-expanded="true">sample text</a>
      </div>
    </div>
    <div id="collapse-SortTechnician-1" class="panel-collapse collapse in" aria-expanded="true" style="">
      <div class="panel-body">
        <div class="block1 block constraint-container no-bg ">
          <div class="constrain content-block clearfix">
            <div class="richtext ">
              <p>sample text</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
以下是我在CSS中尝试过的,但还没有成功

.panel heading a[aria expanded=“true”]~.面板标题{
背景色:#89c2dc;
颜色:#fff;
}

您可以尝试在您的代码中为
[aria expanded=“true”]
添加css。我认为无需编写jQuery来更改折叠时的背景色。我已将折叠用于此面板

a.btn.btn主[aria expanded=“true”]{
背景:红色!重要;
}
.btn.btn主、.btn.btn主:焦点、.btn.btn主:活动{
边界:0;
盒影:无;
}

你好,世界!
切换第二个元素
动物保护协会的陈词滥调,埃尼姆·埃乌斯莫德的高级生命accusamus terry richardson ad squid.尼希尔·凯菲耶·赫尔维蒂卡,工艺啤酒工人韦斯·安德森·克雷德·奈斯库特·智者。
动物保护协会的陈词滥调,埃尼姆·埃乌斯莫德的高级生命accusamus terry richardson ad squid.尼希尔·凯菲耶·赫尔维蒂卡,工艺啤酒工人韦斯·安德森·克雷德·奈斯库特·智者。

您可以尝试更改标题背景色

$(document).ready(function () {
    var anchorElement = $(".panel-heading .panel-title > a");
    if (anchorElement.attr("aria-expanded") == "true") {
        $(anchorElement).closest(".panel-title").css("background-color", '#061544')
    } else {
        $(anchorElement).closest(".panel-title").css("background-color", '#ffffff')
    }
});

谢谢你回答我的问题,但是我有额外的``与bootstrap 4默认折叠代码不太一样,所以这对我不起作用。谢谢。谢谢你回答我的问题。
$(document).ready(function () {
    var anchorElement = $(".panel-heading .panel-title > a");
    if (anchorElement.attr("aria-expanded") == "true") {
        $(anchorElement).closest(".panel-title").css("background-color", '#061544')
    } else {
        $(anchorElement).closest(".panel-title").css("background-color", '#ffffff')
    }
});