【发布时间】:2017-02-16 17:23:19
【问题描述】:
所以我在 Shopify 中有一个模板,如果单击该模板,我会尝试将用户重定向到信息页面。除了该容器中有两个嵌套链接之外,这非常简单。 “了解更多”会转到容器应该进入的页面,但“立即购买”按钮不会。它需要转到立即购买页面。
我使用 jQuery 来完成此操作,因为将整个内容嵌套在锚标记中不起作用。
我目前拥有的 jquery:
$(document).ready(function() {
$(".cross-sell-img-container").click(
function() { window.location = $(this).find(".spec").attr("href");
return false;
});
$(".purchase").click(function() {
window.location = $(this).find(".purchase").attr("href");
return false;
});
//$(".cross-sell-img-container").click(function() {
//window.location = $(this).find("a").attr("href");
//return false;
//});
});
如果我单击任意位置,则在路线中返回未定义。
模板如下所示:
<div class="cross-sell-img-container">
<div class="detailed-cross-sell">
<a href="{{ product.url }}">
<p class="detailed-cross-sell-title">{{ "The " | append: product.title }}</p>
</a>
<div class="detailed-cross-sell-image-container">
{{ product.metafields.custom_fields["spec_preview_image"] | replace: '<img', '<img class="detailed-cross-sell-image"' }}
</div>
<div class="button-container">
{% assign shop_url = product.metafields.custom_fields["domehastore.com_link"] %}
<a href="{% if shop_url %}{{ shop_url }}{% else %}{{ product.url }}#purchasing-area{% endif %}" class="button purchase" target="_blank">
<span class="add-to-cart__text">Buy Now</span>
</a>
<!-- | replace: "/products", "/pages" | append: "-specifications" FP: add after product.url to make go to specs -->
{% assign link_name = product.url %}
<a class="button spec" href="{{ link_name }}">
Learn More
</a>
</div>
</div>
<div class="preview-cross-sell">
<a class="preview-image" href="{{ product.url }}">
{{ product.metafields.custom_fields.cross_sell_preview_image }}
</a>
</div>
</div>
我如何完成我想做的事情?
谢谢!
【问题讨论】:
标签: javascript jquery html shopify liquid