如何在用户单击提交按钮时向搜索URL添加参数?

时间:2017-11-14 08:20:11

标签: jquery shopify

这是我尝试过的,但是在多次提交时,URL中的值字符串没有更新,因此用户仍然可以看到之前的搜索结果' URL。搜索功能(建立在Shopify上)可以正常工作而无需添加参数。任何想法出了什么问题?

表格:

<form id="search" method='get' action="/search">
  <input id="search_text" name="q" class="field" type="text" value="{{ search.terms | remove: ' AND -vendor:Archive AND -tag:Insurance' }}" />
  <input type="hidden" name="type" value="product">
  <input id="search_submit" type="submit" border="0" value="Search" alt="Submit Search"/>
</form>

我的功能:

$('#search input[type="submit"]').click(function(e){
  var excludedCats = ' AND -vendor:Archive AND -tag:Insurance&type=product';
  var new_val = $('#search input[name="q"]').val();
  e.preventDefault();
  location.href = '/search?q=' + new_val + excludedCats;
});

$('.field, textarea').focus(function() {
  if(this.title==this.value) {
    this.value = '';
  }
}).blur(function(){
  if(this.value=='') {
    this.value = this.title;
  }
});

0 个答案:

没有答案