我们如何根据编号附加和删除DIV?

发布于 2025-01-24 14:49:45 字数 2221 浏览 3 评论 0原文

https://prnt.sc/mnw859xpgppq 在这里,我选择了3种产品,仅显示2个产品,只能使用一个文本框,您可以帮助我展示所有3个产品 例如,如果我为set1选择数量2,而set2的数量1则应显示2 set1和1 set2总计3张图像 我得到了我想要的东西,但我坚持根据不同数量选择器来操纵数据,请帮助我摆脱这个问题,谢谢

$(".quantity__input").change(function(){

var img_src =$(this).parents(".atc_coll").find("input[type='hidden']").attr("data-src");
var total = $(this).val();
var oldLength = $(".six_Products > .single_product").length;
var change = total - oldLength;

if (change > 0) {
for (i = 0; i < change; i++) { $(".six_Products").append(`<div class='single_product'><img src='${img_src}'
        style='height:150px; width:150px;'></div>`);
    }
    }
    else {
        change = Math.abs(change)
        $( ".six_Products > .single_product").each(function( index ) {
            $(this).remove();
                if (index == (change -1)) {
                    return false;
                }
        });
    }
});
<div class="six_pack_conatiner ">
    <div class="six_Products">

    </div>
    <div class="atc_price_wrap">
        <a href="javascript:void(0)" class="atc_all_six">Add To Cart</a>
    </div>
</div>

<div class="atc_coll">
    <a href="javascript:void(0)" class="atc_link" data-id="{{ card_product.selected_or_first_available_variant.id }}"
        data->Add To Cart</a>
    <quantity-input class="quantity" style="display:none;">
        <button class="quantity__button no-js-hidden" name="minus" type="button">
            -
        </button>
        <input class="quantity__input" type="number" name="quantity" min="0" value="0" readonly>
        <button class="quantity__button no-js-hidden" name="plus" type="button">
            +
        </button>
    </quantity-input>
    <input type="hidden" data-src="{{ card_product.featured_media | img_url: 'master' }}"
        data_price="{{card_product.price}}">
</div>

https://prnt.sc/mNw859XPGPPQ
Here I have got 3 products selected and its showing only 2 it is works for only one textbox could you please help me to show all 3 products
for example if i select quantity 2 for set1 and quantity 1 for set2 then it should show 2 set1 and 1 set2 total 3 images on top
I got what I want but I am stuck here to manipulate data based on different quantity selector could you please help me to get rid of this problem thank you

$(".quantity__input").change(function(){

var img_src =$(this).parents(".atc_coll").find("input[type='hidden']").attr("data-src");
var total = $(this).val();
var oldLength = $(".six_Products > .single_product").length;
var change = total - oldLength;

if (change > 0) {
for (i = 0; i < change; i++) { $(".six_Products").append(`<div class='single_product'><img src='${img_src}'
        style='height:150px; width:150px;'></div>`);
    }
    }
    else {
        change = Math.abs(change)
        $( ".six_Products > .single_product").each(function( index ) {
            $(this).remove();
                if (index == (change -1)) {
                    return false;
                }
        });
    }
});
<div class="six_pack_conatiner ">
    <div class="six_Products">

    </div>
    <div class="atc_price_wrap">
        <a href="javascript:void(0)" class="atc_all_six">Add To Cart</a>
    </div>
</div>

<div class="atc_coll">
    <a href="javascript:void(0)" class="atc_link" data-id="{{ card_product.selected_or_first_available_variant.id }}"
        data->Add To Cart</a>
    <quantity-input class="quantity" style="display:none;">
        <button class="quantity__button no-js-hidden" name="minus" type="button">
            -
        </button>
        <input class="quantity__input" type="number" name="quantity" min="0" value="0" readonly>
        <button class="quantity__button no-js-hidden" name="plus" type="button">
            +
        </button>
    </quantity-input>
    <input type="hidden" data-src="{{ card_product.featured_media | img_url: 'master' }}"
        data_price="{{card_product.price}}">
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文