keithmoring

动态添加的元素,无法侦听到事件,写法如下:

使用函数.on

格式为:

$(父元素).on(\'event\',\'selector\',function(){

//do something

})

例如

<body>
<
div id=\'test_div\'> <a id=\'a\' class=\'test_a\'>sos</a> </div>
</body>

写为

$(\'body\').on(\'click\',\'.test_a\',function(){
alter($(this).attr(\'id\'))
})

 

 参考http://www.cnblogs.com/lionden/archive/2013/03/21/2973410.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2021-09-20
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案