這是我的代碼,我混合了液體代碼和 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>
uj5u.com熱心網友回復:
試試這個你可以使用jquery通過屬性直接獲取值。
<script>
var handleAttr = $(".hidden_wrap").attr("data-handle");
if(handleAttr){
alert("found");
}else{
alert("not found");
}
</script>
謝謝。
uj5u.com熱心網友回復:
試試這個,對product.handle和 jquery 中的 html 內容使用反引號。:)
& 在copy-of-joory-earrings-tiger-eye-gold后洗掉空白。
<script>
var handle = `{{product.handle}}`;
if ($(`a[class='hidden_wrap'][data-handle=${handle}`).length > 0) {
alert("found");
}
else{
alert('not found');
}
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329098.html
標籤:javascript 查询 购物
