jq append()新增的dom如何控制。live和on都没绑定上

jqappend()新增的dom如何控制
新增的dom无法使用jquery如何解决
javascript$("#addVolumePrice").click(function(){
$("#thisVolumePrice").append(
'
 [-]'+
'优惠数量'+
'优惠价格'
);
});
$(".redVolumePrice").live("click",function(){
alert('111');
});
$(".redVolumePrice").on("click",function(){
alert('111');
});
人到中年有点甜
浏览 363回答 2
2回答

繁花不似锦

$(".redVolumePrice").live("click",function(){alert('111');});$(".redVolumePrice").on("click",function(){alert('111');});这样当然不行的,$("outerSelector").on('eventType','selector',function(){});outerSelector是一个一直存在的DOM,selector是你要监听点击的节点;所以正确的写法是$("#thisVolumePrice").on("click",'.redVolumePrice',function(){alert('111');});具体原理可以搜索javascript事件代理//多谢@nightire的提醒

慕斯709654

这么写试试吧:javascript$('#thisVolumePrice').on('click','.redVolumePrice',function(evt){console.log(evt);//去看看console里打印的evt对象,里面有一些东西很有用。});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript