
<table id="table">
<tr>
<td>11111</td>
</tr>
</table>
<script>
setTimeout(function() {
$('#table').append('<tr><td class="test" id="12">id12</tr><tr><td class="test" id="13">id13</tr><tr><td class="test" id="14">id14</tr>')
}, 1000)
$('#table').on('click', 'td.test', function() {
var test_id = $(this).attr('id')
console.log(test_id)
})
</script>
失效的原因是你仅在页面加载时对元素进行处理,但通过ajax加载的新元素没做处理。
如果你仅需要改变样式,可以在css中通过选择器来实现,如
.first:hover {color:red
}
如果你还需要对其进行其他处理,则需要在ajax的callback中对新加载的元素进行处理,如添加事件等
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)