简体   繁体   English

jQuery Searchbox IE9问题

[英]jQuery Searchbox IE9 issue

I'm working on an issue here that only occurs in IE8/9 我正在处理仅在IE8 / 9中出现的问题

We have 2 search boxes. 我们有2个搜索框。 One in the header that uses jQuery's Autocomplete, and the other which is specifically for an archiving feature we have on certain pages. 标头中的一个使用jQuery的自动完成功能,另一个专用于某些页面上的归档功能。 What should happen is if the Autocomplete searchbox is in focus and we hit Enter after typing something in, it searches with that value. 应该发生的情况是,如果“自动完成”搜索框处于焦点位置,并且在键入某些内容后按下Enter键,它将使用该值进行搜索。 Easy enough. 很简单。

However, in IE8/9, no matter which text box has focus, the Enter key will trigger that event. 但是,在IE8 / 9中,无论哪个文本框具有焦点,Enter键都将触发该事件。

Here's what we've got: 这是我们得到的:

jQuery(".autocomplete").keydown(function(event) {
    if (jQuery(".autocomplete").is(":focus")){
        var query;
        if (event.which === 13) {
          event.preventDefault();
          query = this.value;
          return window.location.href = "/search?q=" + query;
        }
    }
});

I've also tried .keypress() and it yields the same result. 我也尝试过.keypress(),它产生相同的结果。 We're using jQuery 2.0.0 我们正在使用jQuery 2.0.0

Our team is relatively new to jQuery, so we're probably just doing this wrong. 我们的团队是jQuery的新手,所以我们可能只是做错了。

It should only be firing on searchboxes with the .autocomplete class, and only if that particular box has focus. 仅应在具有.autocomplete类的搜索框上触发,并且仅在该特定框具有焦点时才触发。

Thanks! 谢谢!

我很抱歉,显然其他团队添加了一个.js文件,该文件干扰了我们文件中该jquery脚本的运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM