我正在为 bootstrap 崩溃编写 php 代码并出现错误 Cannot read property 'querySelectorAll' of null。我真的花了很多时间来解决这个简单的问题。如果我在没有 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>
最佳答案
这是由于 Bootstrap 4.1.1 或 2 到 4.1.3 的更改。
当你使用 data-parent="selector"
而它应该是 data-parent="#selectorId"
或 data-parent= “.selectorClassName”
。
这个错误过去是悄无声息地作废,但现在它显示这个控制台错误。
关于javascript - 无法读取 null bootstrap 崩溃的属性 'querySelectorAll',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52411316/