我有这个代码,用于在我的网站上搜索。当您填写搜索词并按Enter键时,它将执行命令。但是我想只在用户按下按钮时执行搜索脚本。我无法让它发挥作用。
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点击工作进行搜索。但我想用一个按钮完成它。我希望你们能帮助我解决这个问题。
答案 0 :(得分:0)
点击按钮尝试活动:
<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();
});