假设有一个 jQuery 的
为什么
.each
循环:function reverifyDiscounts() {
//everything we need to verify a discount is already on the page.
//we'll remove the "bad" discounts when we submit the page
console.info("Entering reverification");
//event discounts are always valid once they're on the page because it's for the event
$(".discountPromoItem").each(function () {
//skip events
if ($(this).attr("appliesto") == $("#hdnEventID").val()) {
return true;
}
//we just need to make sure that the checkbox that the appliesto attribute references is checked!
if (!$("checkbox[attribute$='" + $(this).attr("applitesto") + "']").is(":checked")) {
//we also need to remove the promo code from the list of promo codes entered into the hidden textboxes
$("#hdnAppliedPromoCode").val($("#hdnAppliedPromoCode").val().replace($(this).attr("code"), ""));
//the item that it applies to is no longer selected and the promo must be removed
$(this).remove(); //can't remove $(this) while inside the loop for whatever reason.
}
});
recalculate();
}
为什么
$(this).remove()
失败了,或者我做错了什么?
filter
然后再使用remove
。你可以试试吗? - iCollect.it Ltd