当jquery添加新元素后的绑定事件的处理
Java交流学习教室 copy Bookmark http://space.itpub.net/14734416 博客 图片 商品 下载 收藏 影音 圈子 好友 论坛 留言 空间管理 您的位置: ITPUB个人空间 » Java交流学习教室 » 日志 汇聚你我之力...... jquery 新建的元素事件绑定问题(上) 上一篇 / 下一篇 2008-10-20 21:40:00 / 个人分类: jQuery 查看( 1565 ) / 评论( 8 ) / 评分( 30 / 5 ) demo: http://www.cnjquery.com/demo/jquery页面加载完成后元素绑定事件.html 我想很多人都会向我一样曾经 被新元素的事件绑定困惑很久也就是 在页面加载完成后给元素绑定了事件,但又新增加的元素上却没有绑定任何事件。 js的事件监听跟css不一样,css只要设定好了样式,不论是原来就有的还是新添加的,都有一样的表现。而事件监听不是,你必须给每一个元素单独绑定事件。 常见的例子是处理表格的时候。每行行末有个删除按钮,点了这个能够删除这一行。 < table > < tbody > < tr > < td > 这行原来就有 </ td > < td >< button class = " del " > 删除 </ button ></ td > </ tr > < tr