gpt4 book ai didi

javascript - 当其他产品选项更改时选择产品数量

转载 作者:行者123 更新时间:2023-11-29 20:49:00 25 4
gpt4 key购买 nike

我试图在产品选项更改时选择数量值。我已经尝试了各种 jquery 函数,但我进展得并不快。我还必须考虑更新多个产品。我需要选择数量,以便在更改选项时将所有选项/数量传递到后端。

有人可以帮忙吗?

这是一个 jsfiddle显示我的 html/jquery。

我想也许我可以遍历每个 .qty类并找到 .list .qty <select>元素,但我运气不佳。

$(".qty").each(function()
{
// var name = $(this).attr('name');
// console.log(name);
//var x=$('.list').closest('select').find(':selected').val(); //find the value
var x=$('.qty').siblings('.list'); //find the value
console.log(x);
});

最佳答案

使用.list select 获取每个选择列表:

$('.list select').each(function()
{
$(this).find('option').each(function() {
console.log($(this).val(), $(this).text());
}); //find the value


});

对于 select with class qty 的值,使用可以简单地使用:

var qty = $('select.qty option:selected').val();

console.log(qty);

关于javascript - 当其他产品选项更改时选择产品数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52871011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com