如何检查元素是否具有此值

how to check if element has this value or not

这是我的代码,我混合了 liquid 代码和 js 我得到了产品句柄,但是如果条件不起作用我有带有属性值的标签仍然显示找不到有人可以帮助我解决这个问题

<a class="hidden_wrap" name="hidden_link" data-color="gold" data-stone="tiger-eye" data-handle="copy-of-joory-earrings-tiger-eye-gold
" style="appearance: auto;"> gold-tiger-eye   </a>

<script>
          var handle = "{{product.handle}}";
         if ($(`a[class='hidden_wrap'][data-handle='${handle}').length > 0) {
                    alert("found");
                  }else
                  {

              alert('not found');
          }
</script>
            

试试这个, product.handle 以及 jquery 中的 html 内容使用反引号。 :)

& 在 copy-of-joory-earrings-tiger-eye-gold.

之后删除白色 Space
<script>
     var handle = `{{product.handle}}`;
     if ($(`a[class='hidden_wrap'][data-handle=${handle}`).length > 0) {
          alert("found");
     }
     else{
          alert('not found');
     }
</script>

试试这个 您可以使用 jquery.

直接通过属性获取值
<script>
var handleAttr = $(".hidden_wrap").attr("data-handle");
if(handleAttr){
alert("found");
}else{
alert("not found");
}
</script>

谢谢。