无法读取null引导程序崩溃的属性'querySelectorAll' [英] Cannot read property 'querySelectorAll' of null bootstrap collapse
问题描述
我正在编写引导程序崩溃的PHP代码,并报错无法读取null的属性'querySelectorAll'.我花了很多时间解决这个简单的问题.如果我没有php就可以正常工作而不会出错 错误是:
I am writing php code for bootstrap collapse and taking error Cannot read property 'querySelectorAll' of null. I spend really a lot of time to this simple problem. If I put without php that is working really norm without error Error is:
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所致.
This is due to a change in Bootstrap 4.1.1 or 2 to 4.1.3.
当您使用data-parent="selector"
时,会出现相同的错误,而它应该是data-parent="#selectorId"
或data-parent=".selectorClassName"
.
Same error happens when you use data-parent="selector"
while it should be data-parent="#selectorId"
or data-parent=".selectorClassName"
.
该错误曾经无声地消失,但现在显示此控制台错误.
This error used to void silently but now it displays this console error.
这篇关于无法读取null引导程序崩溃的属性'querySelectorAll'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!