Javascript 使用Jquery复选框类型Add To Cart动态调用Shopify产品ID
*解决方案位于底部* 这个我有点麻烦 以下是我所拥有的: 我在我的产品页面上有一个自定义追加销售,我所说的自定义是指: 追加销售复选框:Javascript 使用Jquery复选框类型Add To Cart动态调用Shopify产品ID,javascript,jquery,html,css,shopify,Javascript,Jquery,Html,Css,Shopify,*解决方案位于底部* 这个我有点麻烦 以下是我所拥有的: 我在我的产品页面上有一个自定义追加销售,我所说的自定义是指: 追加销售复选框: <ul class="upsell" style="margin-left:0px; margin-top:5px;"> <li> <label> <img src="https://cdn.shopify.com/s/files/1/0386/0093/t/15/assets/.jpg
<ul class="upsell" style="margin-left:0px; margin-top:5px;">
<li>
<label>
<img src="https://cdn.shopify.com/s/files/1/0386/0093/t/15/assets/.jpg? 14998" width="40px" height="40px" >
<input type="checkbox" id="chks1"/><span>Product Title <span>$9.99</span> </span></label>
</li>
<li>
<label>
<img src="https://cdn.shopify.com/s/files/1/0386/0093/t/15/assets/.jpg?14998" width="40px" height="40px" >
<input type="checkbox" id="chks1"/><span>Product Title <span>$9.99</span> </span></label>
</li></ul>
很好用——希望对任何人都有帮助。试试看-
这是产品页面上的工作
$(document).ready(function(){
var idProduct = $('#ProductSelect-product-template').val();
console.log(idVar);
});
你说的是
var productID=//什么;post('/cart/change.js',{quantity:0,id:productID})代码>您可以回答自己的问题。。。见:
<ul class="upsell" style="margin-left:0px; margin-top:5px;">
{% for product in collections.name.products limit:4 %}
<li{% cycle ' style="clear:both;"', '', '', ' class="last"' %}>
<label>
<img src="{{ product.featured_image | product_img_url: 'thumb' }}">
<input type="checkbox" id="chks{{ forloop.index }}"><span>{{ product.title }} < span> {{ product.price | money }} </span></span> </label>
</li>
{% endfor %}
</ul>
</div>
<script>
function triggerChange(){
$('#chks1').trigger("change");
}
$('#chks1').change(function() {
if(this.checked) {
jQuery.post("/cart/add.js", { quantity: 1, id: 262626 });
} else {
jQuery.post('/cart/change.js', { quantity: 0, id: 2626262 });
}
});
</script>
<ul class="upsell" style="margin-left:0px; margin-top:5px;">
{% for product in collections.atc-cart-checkbox.products limit:4 %}
<li{% cycle ' style="clear:both;"', '', '', ' class="last"' %} >
<label>
<img src="{{ product.featured_image | product_img_url: 'thumb' }}">
<input type="checkbox" id="product-{{ product.variants.first.id }}" name="id" value="{{ product.variants.first.id }}" class="product-select-{{ product.id }}"/><span>{{ product.title }} <span class="upsellprice">
{{ product.price | money }}<span class="was_price"> {% if product.price < product.compare_at_price_min %}
{{ product.compare_at_price_min | money }}{% endif %}</span></span></span> </label>
</li>
<script type="text/javascript">
$('#product-{{ product.variants.first.id }}').change(function() {
if(this.checked) {
jQuery.post("/cart/add.js", { quantity: 1, id: {{ product.variants.first.id }} });
}
else {
jQuery.post('/cart/change.js', { quantity: 0, id: {{ product.variants.first.id }} });
}
});
</script>
{% endfor %}
</ul>
$(document).ready(function(){
var idProduct = $('#ProductSelect-product-template').val();
console.log(idVar);
});