0

ボタンをクリックするときに、以下の URL の末尾に「+20-30」を追加したいと考えています。

現在私は持っています: mydomain.com/collections/mens/white

URL を 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 %}

  }
 });
4

3 に答える 3

1
var newhefc = $(this).attr('href') + '+20-30';
$(this).attr('href', newhefc);

またはより直接的に:

$(this).attr( 'href', $(this).attr('href') + '+20-30' );

あなたの編集を見ると、他のすべてが等しく、機能しているので、固定文字列を追加したいだけなら、

jQuery(this).attr("href", newhref + '+20-30')
于 2012-10-14T22:41:42.977 に答える
1

hrefリンクの を更新しているとします。

$(this).attr('href', function(i,h) { return h + '+20-30'; });

または、より簡単に:

this.href += '+20-30';

jQuery は必ずしもhref必要ではありませんが、jQuery メソッドは属性内で見つかったものを正確に返すのに対し、ネイティブ DOM アプローチ (2 番目の例) は絶対/「解析済み」の完全な URLを返すことを覚えておくことが重要です。

(これらの例には、this(したがって$(this)) 属性を更新しようとしている関連a要素を参照するという明示的な仮定が含まれていhrefます。)

于 2012-10-14T22:43:11.793 に答える
0

http://wiki.shopify.com/Link_to_tagをご覧ください

これにより、液体を使用して URL が作成されます。

于 2012-10-15T01:15:14.667 に答える