$(document).on("click", '.goToInvocationList', function(){
<a href="#" id="create">Create slides</a>
});
加载页面后,此链接将附加ajax 当我点击此链接时,它假设创建幻灯片,但它给了我这个错误 未捕获的TypeError:无法读取属性&#39; className&#39;未定义的。 但是当我把click事件放在一个没有附加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>
答案 0 :(得分:0)
创建链接后添加侦听器:
$(document).on("click", '.goToInvocationList', function(){
$(something).append("<a href='#' id='create'>Create slides</a>")
$('#create').on('click',function(){sildes_create();})
});