我有通过 php 代码动态生成的列表。我想通过单击删除行。我的代码第一次工作正常,第二次工作正常
HTML
<li>
<div class="pers-left-container">
<img src="<?php echo $cProduct['thumb']; ?>" />
</div>
<div class="pers-right-container">
<span class="sidebar-product-name"><?php echo $cProduct['name']; ?></span>
<a href="javascript:void(0);" class="close-container-product removeItem">X
<form id="removeItemForm" method="post" >
<input type="hidden" value="<?php echo $cProduct['product_id']; ?>" name="removeProductId" class="removePID" />
</form>
</a><br />
<label>Qty: </label><input type="number" value="1" min="0" max="100" step="5" /><br />
<span class="price-container-product">Amt: <?php echo $cProduct['price']; ?></span>
</div>
<div class="clearfix"></div>
</li>
JS
$( ".removeItem" ).each(function(index) {
$(this).click("click", function(){
//var otherInput = $(this).find('.pID').val();
removePID = {'removeProductId':$(this).find('.removePID').val()}
alert(removePID['removeProductId']);
$.ajax({
type:"post",
url:"index.php?route=common/personaliseyourflowers",
data:removePID,
success:function(response){
//alert(response);
if(response) {
$(".reloadCOnt").load(window.location + " .reloadCOnt");
}
//} else {
//$(".reloadCOnt").load(window.location + " .reloadCOnt");
//}
}
});
});
});
任何人都可以指导我哪里错了。我会感谢
最佳答案
.在.each内部单击?!!使用 $('body').on('click' , 选择器 , function(){});
$( 'body' ).on("click",".removeItem", function(){
//var otherInput = $(this).find('.pID').val();
removePID = {'removeProductId':$(this).find('.removePID').val()}
alert(removePID['removeProductId']);
$.ajax({
type:"post",
url:"index.php?route=common/personaliseyourflowers",
data:removePID,
success:function(response){
//alert(response);
if(response) {
$(".reloadCOnt").load(window.location + " .reloadCOnt");
}
//} else {
//$(".reloadCOnt").load(window.location + " .reloadCOnt");
//}
}
});
});
关于javascript - 使用 jquery 第二次点击不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34199391/