jquery 操作动态添加的元素

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

使用函数.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

posted @ 2014-01-21 01:09  KeithMorning  阅读(248)  评论(0编辑  收藏  举报