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
作者:KeithMorning
出处:http://www.cnblogs.com/keithmoring/
关于作者:欢迎转载,且在文章页面明显位置给出原文链接
如有问题,可以通过keith@keithmorning.com 联系我,非常感谢。