类列表显示错误。我正在使用色板来选择变体,我想将jQuery转换为纯javascript以进行选择?

时间:2018-10-30 06:59:27

标签: javascript shopify

 <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新手

1 个答案:

答案 0 :(得分:0)

这是错误的

.swatch[data-option-index="{{ option_index }}"].{{ value | handle }}

尝试一下

.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}