单击按钮时,我想在下面的 URL 末尾添加“+20-30”。
目前我有:mydomain.com/collections/mens/white
我希望我的网址是 mydomain.com/collections/mens/white+20-30
<div class="clearfix filter">
{% assign tags = 'White, Grey, Tan, Neutral, Blue, Black' | replace: ' ,', ',' | replace: ', ', ',' | split: ',' %}
<p>Filter Color</p>
<div id="dd" class="mywrap-dropdown-2" tabindex="2">Select
<ul class="dropdowner" id="coll-filter">
<li><a href="">All</a></li>
{% for tag in tags %}
{% if current_tags contains tag %}
<li><a href="{{ tag | handle }}" class="selected">{{ tag }}</li>
{% elsif collection.all_tags contains tag %}
<li><a href="{{ tag | handle }}">{{ tag }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
jQuery:
$('#coll-filter li a').on('click', function () {
var newTags = [];
jQuery('#coll-filter li a').each(function() {
if (jQuery(this).attr('href')) {
newTags.push(jQuery(this).attr('href'));
}
});
if (newTags.length) {
var query = newTags.join('+');
var newhref = jQuery('{{ 'tag' | link_to_tag: 'tag' }}').attr('href').replace('tag', query);
jQuery(this).attr("href", newhref)
}
else {
{% if collection.handle %}
window.location.href = '/collections/{{ collection.handle }}';
{% elsif collection.products.first.type == collection.title %}
window.location.href = '{{ collection.title | url_for_type }}';
{% elsif collection.products.first.vendor == collection.title %}
window.location.href = '{{ collection.title | url_for_vendor }}';
{% endif %}
}
});