gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'className' of undefined?

转载 作者:行者123 更新时间:2023-11-28 11:03:33 25 4
gpt4 key购买 nike

$(document).on("click", '.goToInvocationList', function(){
<a href="#" id="create">Create slides</a>
});

此链接在加载页面后由 ajax 附加当我单击此链接时,它应该创建幻灯片,但它给了我这个错误未捕获的类型错误:无法读取未定义的属性“className”。但是当我将点击事件放在一个没有附加 javascript 的链接上时,它工作正常

$(document).on("click", '.go-invoice', function(){
sildes_create();
document.location.href='#invoce';

});
<div class="swiper-container">
<div class="swiper-wrapper"></div>
<span class="pagination"></span>
</div>

<script>
function sildes_create(){
count = 4;
var mySwiper = new Swiper('.swiper-container',{
pagination: '.pagination',
paginationClickable: true
});

for ( var i =0; i < 3; i++){
mySwiper.createSlide('<div class="title" style="color:#000">Slide '+ (++count)+'</div>', 'swiper-slide #000-slide').insertAfter(0);
}
}
</script>

最佳答案

创建链接后添加监听器:

   $(document).on("click", '.goToInvocationList', function(){
$(something).append("<a href='#' id='create'>Create slides</a>")
$('#create').on('click',function(){sildes_create();})
});

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

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