在 ENTER 上提交搜索在 IE 中不起作用 [英] Submit search on ENTER not working in IE

查看:23
本文介绍了在 ENTER 上提交搜索在 IE 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要执行全文搜索,用户只想将他们的查询输入到简单的 inputText 中.然后只要他们按下 ENTER 搜索本身就会开始.

to perform a fulltext search users want to simply enter their query into a simple inputText. Then as soon as they hit ENTER the search itself should kick in.

目前我们尝试这样解决:

Currently we tried to solve it like this:

  • inputText 绑定到 sessionScope 变量 myQuery
  • 输入还有一个绑定到其 onchange 事件的 OpenPage 操作
  • 要打开的页面包含一个带有绑定到 sessionScope 变量的搜索过滤器的 viewPanel,以及一些更多的 FT 过滤字段.
  • the inputText is bound to a sessionScope variable myQuery
  • the input also has an OpenPage action bound to its onchange event
  • the page that is to be opened contains a viewPanel with a search filter bound to our sessionScope variable, as well as some more FT filtering fields.

这在 Firefox 和 Chrome 中运行良好但不适用于 IE;显然 IE 没有将 ENTER 键识别为 onchange-trigger.

This works fine in Firefox and Chrome but not in IE; obviously IE isn't recognizing the ENTER key as an onchange-trigger.

所以我尝试使用像

var q=sessionScope.get("myQuery");
return q.charCodeAt(q.length-1);

适用于所有标准字符,但不适用于 ENTER 键(我预计会收到代码 13).

Works fine for all standard characters, but not for the ENTER key (where I would have expected to receive code 13).

我目前确实有一些在控件的 onkeyup 事件中使用 CSJS 代码的解决方法,如下所示:

I currently do have some kind of workaround using CSJS code in the control's onkeyup event as in:

if(event.keyCode===13){
    var p=location.pathname.split("/");
    p.pop();
    location.replace(p.join("/") + "/search.xsp");
}

但这有一些副作用,有可能使事情变得更复杂,感觉有点像黑客.所以我更愿意使用服务器端脚本来解决它.

But this has some side effects which has some potential to make things more complicated, and it feels a bit like some hack. So I'd prefer to solve it using server side scripting.

问题是:

  • 有没有办法捕获 ENTER 键击,以便我们可以对其做出反应?
  • 或者我们可能在一个完全错误的轨道上?

推荐答案

在 IE 中,onchange 事件在输入失去焦点之前不会被触发:http://komlenic.com/231/internet-explorer-onchange-on-enter/

In IE the onchange event is not fired until the input loses focus: http://komlenic.com/231/internet-explorer-onchange-on-enter/

所以你可以使用一些 CSJS 来捕捉 IE 中的 ENTER 键,并使用 .blur() 方法从输入中删除焦点,这将依次触发 onchange 活动

So you could use some CSJS to catch the ENTER press in IE, and drop focus from the input using .blur() method, which will in turn trigger the onchange event

我试过的一个简单的例子似乎有效:

A quick example I tried out that seems to work:

<xp:inputText id="inputText2" value="#{document1.text1}">
    <xp:eventHandler event="onkeyup" submit="false">
        <xp:this.script><![CDATA[
            var kc = thisEvent.keyCode?thisEvent.keyCode:"";
            if(kc != "" && kc == "13") {
                var input = dojo.byId("#{id:inputText2}");
                input.blur();
            }]]>
        </xp:this.script>
    </xp:eventHandler>
    <xp:eventHandler event="onchange" submit="true" refreshMode="complete">
        <xp:this.action>
            <xp:openPage name="/formInput.xsp"></xp:openPage>
        </xp:this.action>
    </xp:eventHandler>
</xp:inputText>

这篇关于在 ENTER 上提交搜索在 IE 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆