无法读取空引导折叠的属性“querySelectorAll”

2022-08-30 17:04:03

我正在为引导折叠编写php代码,并采取错误无法读取空值的属性“querySelectorAll”。我花了很多时间在这个简单的问题上。如果我放没有php,这是工作真正规范没有错误错误是:

Uncaught TypeError: Cannot read property 'querySelectorAll' of null
at a.t._getParent (collapse.js:300)
at new a (collapse.js:88)
at HTMLDivElement.<anonymous> (collapse.js:345)
at Function.each (jquery.js:368)
at jQuery.fn.init.each (jquery.js:157)
at jQuery.fn.init.a._jQueryInterface [as collapse] (collapse.js:331)
at HTMLDivElement.<anonymous> (collapse.js:378)
at Function.each (jquery.js:368)
at jQuery.fn.init.each (jquery.js:157)
at HTMLButtonElement.<anonymous> (collapse.js:374)

这是我的php代码

<div id="info-content" class="accordion" id="accordionExample">
                  <?
                    $faqs = get_field('faqs');
                    foreach ($faqs as $key => $value):
                  ?>
                  <div class="card">
                    <div class="card-header" id="headingOne<?=$key;?>">
                      <h5 class="mb-0">
                        <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne<?=$key;?>" aria-expanded="true" aria-controls="collapseOne<?=$key;?>">
                          <?=$value['question'];?>
                        </button>
                      </h5>
                      <i class="fas fa-plus"></i>
                    </div>
                    <div id="collapseOne<?=$key;?>" class="collapse <?if($key==0):?>show<?endif;?>" aria-labelledby="headingOne<?=$key;?>" data-parent="#accordionExample">
                      <div class="card-body">
                        <?=$value['answer'];?>
                      </div>
                    </div>
                  </div>
                  <?endforeach;?>
                </div>

答案 1

这是由于 Bootstrap 4.1.1 或 2 到 4.1.3 中的更改。

当您使用时,也会发生相同的错误,而它应该是 或 。data-parent="selector"data-parent="#selectorId"data-parent=".selectorClassName"

此错误以前以静默方式取消,但现在它显示此控制台错误。


答案 2

我也有同样的问题。对我来说,这是由于主导航栏容器中丢失了。请参阅以下内容,ididul

<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
   <!-- Nav Item - Dashboard -->
   <li class="nav-item">
    <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseUtilities" aria-expanded="true" aria-controls="collapseUtilities">
      <i class="fas fa-fw fa-wrench"></i>
      <span>Utilities</span>
    </a>
    <div id="collapseUtilities" class="collapse" aria-labelledby="headingUtilities" data-parent="#accordionSidebar">
      <div class="bg-white py-2 collapse-inner rounded">
        <h6 class="collapse-header">Custom Utilities:</h6>
        <a class="collapse-item" href="utilities-color.html">Colors</a>
        <a class="collapse-item" href="utilities-border.html">Borders</a>
        <a class="collapse-item" href="utilities-animation.html">Animations</a>
        <a class="collapse-item" href="utilities-other.html">Other</a>
      </div>
    </div>
 </li>     
</ul>

希望这有助于某人。

干杯。