动态插入的html代码,点击节点无效以及获取节点下标的方法

动态插入的html,需要使用delegate或者on事件来监听,方式如下。 如果需要获取节点对应的下标,$(this).index()是无法获取的,需要以$(selectot).index(this)方式来获取

$('body').on('click', '.delete-pic', function () {
console.log($('.delete-pic').index(this))
  const index =
$('.delete-pic').index(this)

})
当需要使用该下标执行操作时,最好先使用一个变量index存起来
posted @ 2019-06-13 14:50  陈小作  阅读(408)  评论(0编辑  收藏  举报