单击输入字段中的键盘事件的链接

时间:2016-02-17 21:13:40

标签: javascript firefox xpages

我有一个搜索输入字段,想要在用户输入搜索短语后按Enter键时激活搜索。我还有一个链接控件,SSJS重定向到另一个XPage(并将添加一些我使用SSJS的参数,所以只使用CSJS打开另一个页面不是一个选项)。这在Chrome中效果很好但在Firefox中什么都不做。有人有什么建议吗?

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:inputText id="inputText1" style="width:142.0px">
    <xp:eventHandler
        event="onkeyup"
        submit="false">
        <xp:this.script><![CDATA[if (typeof thisEvent == 'undefined' &&     window.event) { thisEvent = window.event; }
if (thisEvent.keyCode == dojo.keys.ENTER)
{
dojo.byId("#{id:searchButton}").click();
thisEvent.preventDefault();
}]]></xp:this.script>
    </xp:eventHandler></xp:inputText>
<xp:link
    escape="true"
    text="Search"
    id="searchButton">
    <xp:eventHandler
        event="onclick"
        submit="true"
        refreshMode="complete"
        disableValidators="true">
        <xp:this.action><![CDATA[#    {javascript:context.redirectToPage("search.xsp");}]]></xp:this.action>
    </xp:eventHandler>
</xp:link></xp:view>

1 个答案:

答案 0 :(得分:1)

我有类似的功能,可以在Firefox中按预期工作。不同之处在于我使用onkeypress而不是onkeyup:

<xp:inputText id="searchName" value="#{viewScope.searchName}">
    <xp:eventHandler event="onkeypress" submit="false">
        <xp:this.script><![CDATA[
            if (typeof thisEvent == 'undefined' && window.event) { thisEvent = window.event; }
            if (thisEvent.keyCode == dojo.keys.ENTER)
            {
                dojo.byId("#{id:searchButton}").click();
                thisEvent.preventDefault();
            }
        ]]></xp:this.script>
    </xp:eventHandler>
</xp:inputText>
相关问题