首页 > 解决方案 > 更改其他产品选项时选择产品数量

问题描述

我正在尝试在更改产品选项时选择数量值。我尝试了各种 jquery 函数,但我没有快速获得任何进展。我还必须考虑更新多个产品。我需要选择数量,以便在更改选项时,所有选项/数量都传递给后端。

有人能帮忙吗?

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

我想也许我可以遍历每个.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);
});

标签: javascriptjquery

解决方案


用于.list select抓取每个选择列表:

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


});

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

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

console.log(qty);

推荐阅读