未捕获的TypeError: Cannot read property '的定义

Uncaught TypeError: Cannot read property 'className' of undefined?

本文关键字:property read 定义 Cannot TypeError      更新时间:2023-09-26
$(document).on("click", '.goToInvocationList', function(){
 <a href="#" id="create">Create slides</a>
});

此链接在加载页面后由ajax添加当我点击这个链接时,它应该创建幻灯片但它给了我这个错误未捕获的类型错误:无法读取未定义的属性"className"。但是当我把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> 

在创建链接后添加侦听器:

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