gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property '0' of null

转载 作者:行者123 更新时间:2023-11-29 15:39:24 25 4
gpt4 key购买 nike

我在控制台日志中收到“未捕获的类型错误:无法读取 null 的属性‘0’”请注意,我使用的代码在 jsfiddle 上运行良好但我的博客里没有

blog url

JavaScript 代码

<script type="text/javascript">
//<![CDATA[[
$(document).ready(function(){
$('.widget-content').each(function(){
var hg = $(this).html(),
qsqs = hg.match(/[^[\]]+(?=])/g);
alert(qsqs[0]);
});
});
//]]>
</script>

最佳答案

问题是您有另一个带有 widget-content 类的 div,它导致 jquery 选择器在两者中运行。

例子

<div class="widget-content">
[2][Sport][Two]
</div>
<div class="widget-content">
.
</div>

这里更新了 Fiddle,因此您可以清楚地看到错误:http://jsfiddle.net/679JJ/1/

关于javascript - 未捕获的类型错误 : Cannot read property '0' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22160700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com