javascript - 更改其他产品选项时选择产品数量
问题描述
我正在尝试在更改产品选项时选择数量值。我尝试了各种 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);
});
解决方案
用于.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);
推荐阅读
- java - 在 Java 中使用泛型接口作为方法参数
- c# - 使用 Apache Docker 在 Linux 中托管 ASP.NET Core
- c - 释放链表内存时的 valgrind 错误
- python - 来自子解析器的顶级解析器上的 Python argparse set_defaults
- c# - 在 macOS 上读取引导扇区 CD 驱动器
- vue.js - Vue 渲染一个组件两次
- python - 如何在字典中无序搜索?
- java - 如何在自动化 selenium 测试用例时将命令传递给开发控制台
- mongodb - 为什么猫鼬不允许我在 _id 上通过 $in 查找,除非我有一个包含另一个模式的模式?
- python - Python标量转换一个数组