我有一个房地产插件,我使用我的网站。这个插件的搜索工具不能与键盘上的回车键一起工作。我想在搜索工具中输入关键字后用回车键搜索。我怎么能做到呢?
我的网站:https://memoshome.com
我认为相关代码是这样的:
$('.ere-advanced-search-btn', css_class_wrap).on('click', function (e) {
e.preventDefault();
var search_form = $(this).closest('.search-properties-form'),
search_url = search_form.data('href'),
search_field = [],
query_string = '?';
if (search_url.indexOf('?') !== -1) {
query_string = '&';
}
$('.search-field', search_form).each(function () {
var $this = $(this),
field_name = $this.attr('name'),
current_value = $this.val(),
default_value = $this.data('default-value');
if (current_value != default_value) {
search_field[field_name] = current_value;
}
});
$('.ere-sliderbar-filter', search_form).each(function () {
var $this = $(this),
field_name_min = $this.find('.min-input-request').attr('name'),
field_name_max = $this.find('.max-input-request').attr('name'),
current_value_min = $this.find('.min-input-request').val(),
current_value_max = $this.find('.max-input-request').val(),
default_value_min = $this.data('min-default'),
default_value_max = $this.data('max-default');
if (current_value_min != default_value_min || current_value_max != default_value_max) {
search_field[field_name_min] = current_value_min;
search_field[field_name_max] = current_value_max;
}
});
var other_features = '';
$('[name="other_features"]', search_form).each(function () {
var $this = $(this),
value = $this.attr('value');
if ($this.is(':checked')) {
other_features += value + ";";
}
});
if (other_features !== '') {
other_features = other_features.substring('0', other_features.length - 1);
search_field['other_features'] = other_features;
}
if (search_field !== []) {
for (var k in search_field) {
if (search_field.hasOwnProperty(k)) {
query_string += k + "=" + search_field[k] + "&";
}
}
}
query_string = query_string.substring('0', query_string.length - 1);
window.location.href = search_url + query_string;
});
我认为用'submit'
代替'click'
可以工作,如果你把它添加到你的btntype="submit"
没有HTML代码,您可以尝试:
$('.my-search-box').keydown((ev) => {//i suppose .my-search-box' is class of input search
if (ev.which == 13 ){//enter
$('give the id/class of button search').trigger("click");
}
});
如果事件被输入到输入搜索框中,那么你触发点击按钮搜索
在您的搜索输入文本框中,尝试这样做:
$('.my-search-box').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$('.ere-advanced-search-btn', css_class_wrap).click();
return;
}
});