【发布时间】:2018-01-08 20:56:56
【问题描述】:
所以我有一个产品的下拉选择。我只想在检查输入时添加一个类。我知道使用 css 你可以识别 input:checked 但我需要一个额外的来进一步开发。 这是我的代码的一部分
for (var i=0,length=variant.options.length; i<length; i++) {
var radioButton = $productForm.find('.swatch[data-option-index="' + escape(i) + '"] :radio[value="' + variant.options[i].replace(/\"/g,'\\"') +'"]');
if (radioButton.length) {
radioButton.get(0).checked = true;
}
}
我尝试以这种方式添加类:
if (radioButton.length) {
radioButton.get(0).checked = true.addClass("selected");;
}
这样
if (radioButton.length) {
radioButton.get(0).checked = true;
radioButton.get(0).addClass("selected");
}
这两种方法都不起作用,我不明白为什么。
【问题讨论】:
标签: jquery select input shopify checked