使用jquery的append方法添加了一个div,然后取不到div中的元素,怎么办?谢谢各位大神!
$(document).ready(function(){$.each($(".shop-cartbutton"),function(i,val){$(this).cli...
$(document).ready(function(){
$.each($(".shop-cartbutton"), function(i,val){
$(this).click(function(){
$(".ng-isolate-scope").show();
$("#shopbasket .ng-isolate-scope").append("<div class='shop-cartbasket-tablerow'>"+
"<div class='cell itemname'>"+$(this).parents("span").siblings().find("h3").text()+"</div>"+
"<div class='cell itemquantity'>"+
"<button id='reduce'>-</button>"+
"<input class='ng-pristine ng-valid' value='1'>"+
"<button id='addtion'>+</button>"+
"</div>"+
"<div class='cell itemtotal ng- binding'>"+$(this).parents("span").prev().text()+"</div>"+
"</div>");
});
});
$("#reduce").on("click",function(){
alert("122121");
});
}); 展开
$.each($(".shop-cartbutton"), function(i,val){
$(this).click(function(){
$(".ng-isolate-scope").show();
$("#shopbasket .ng-isolate-scope").append("<div class='shop-cartbasket-tablerow'>"+
"<div class='cell itemname'>"+$(this).parents("span").siblings().find("h3").text()+"</div>"+
"<div class='cell itemquantity'>"+
"<button id='reduce'>-</button>"+
"<input class='ng-pristine ng-valid' value='1'>"+
"<button id='addtion'>+</button>"+
"</div>"+
"<div class='cell itemtotal ng- binding'>"+$(this).parents("span").prev().text()+"</div>"+
"</div>");
});
});
$("#reduce").on("click",function(){
alert("122121");
});
}); 展开
展开全部
$(document).ready(function(){
$.each($(".shop-cartbutton"), function(i,val){
$(this).click(function(){
$(".ng-isolate-scope").show();
$("#shopbasket .ng-isolate-scope").append("<div class='shop-cartbasket-tablerow'>"+
"<div class='cell itemname'>"+$(this).parents("span").siblings().find("h3").text()+"</div>"+
"<div class='cell itemquantity'>"+
"<button id='reduce'>-</button>"+
"<input class='ng-pristine ng-valid' value='1'>"+
"<button id='addtion'>+</button>"+
"</div>"+
"<div class='cell itemtotal ng- binding'>"+$(this).parents("span").prev().text()+"</div>"+
"</div>");
$("#reduce").on("click",function(){
alert("122121");
});
});
});
});
因为这个div是代码生成的,那么事件就在生成的代码跟着写。我测试是可行的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询