【问题标题】:Search form with button带按钮的搜索表单
【发布时间】:2016-03-03 07:47:58
【问题描述】:

我有这段代码,用于在我的网站上进行搜索。当您填写搜索词并按回车键时,它将执行命令。但是,我只想在用户按下按钮时执行搜索脚本。我无法让它工作。

jQuery(document).ready(function($){
    var input = $('[data-search-input]');
    input.on('keypress', function(event) {
        if (event.which == 13 && input.val().length > 3) {
            event.preventDefault();
            window.location.href = input.data('search-input') + '{{ config.system.param_sep }}' + input.val();
        }
    });
});
<input class="zoekveld" type="text" placeholder="Zoeken..." value="{{ query }}" data-search-input="{{ base_url }}{{ config.plugins.simplesearch.route}}/query" />

如您所见,我使用 javascript 来使按 Enter 进行搜索点击工作。但我希望它通过一个按钮来完成。我希望你们能帮助我解决这个问题。

【问题讨论】:

标签: javascript jquery html search


【解决方案1】:

点击按钮尝试事件:

 <button id="yourbutton" class="zoekbutton">Zoek</button>
    $('#yourbutton').on('click',function(e){
          e.preventDefault();
          var input = $('[data-search-input]');
         window.location.href = input.data('search-input') + '{{ config.system.param_sep }}' + input.val();

    });

【讨论】:

  • 所以我这样做了: 还是没有效果..
  • yourbutton 是一个变量,我已将其更改为 id
  • 仍然没有任何效果..还有其他解决方案吗?
  • 非常感谢您的帮助。但它仍然没有给我任何效果
  • 你期待什么效果?
猜你喜欢
  • 2012-06-19
  • 2017-04-21
  • 2013-12-05
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
相关资源
最近更新 更多