<script>
jQuery('.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}').removeClass('soldout').addClass('available').find(':radio').removeAttr('disabled');
</script>
我一直在努力将其转换为纯JavaScript。 我已经尝试了以下代码
<script>
document.querySelector('.swatch[data-option-index="{{ option_index }}"].{{ value | handle }}').classList.remove('soldout').classList.add('available').find(':radio').removeAttribute('disabled');
</script>
但是我得到未捕获的TypeError:无法读取未定义的属性'classList' 请帮我解决这个问题。我是javascript新手
答案 0 :(得分:0)
这是错误的
.swatch[data-option-index="{{ option_index }}"].{{ value | handle }}
尝试一下
.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}