XPages - onkeypress事件未正确触发点击 [英] XPages - onkeypress event not triggering click properly

查看:114
本文介绍了XPages - onkeypress事件未正确触发点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xpages自定义控件创建了一个搜索字段(id:searchField)和一个搜索按钮(id:searchButton)。我在搜索字段上添加了一个onkeypress事件,这样它就会触发对searchButton的点击。然后,searchButton将重新加载页面,但url参数来自搜索字段。问题是页面重新加载,但是当我在搜索字段中按下时,搜索参数不会添加到URL ,但是当我按下searchButton时工作正常。以下是我使用的代码:

I created a search field (id:searchField) and a search button (id:searchButton) using Xpages Custom Controls. I added an onkeypress event on the search field such that it will trigger a click to the searchButton. The searchButton will then reload the page but with url parameters coming from the search field. The problem is that the page reloads but the search parameters are not added to the URL when I press ENTER in the search field, but works properly when I press searchButton. Here are the codes I used:

(代码添加到searchField的onkeypress)


if (typeof thisEvent == 'undefined' && window.event) { thisEvent = window.event; }
if (thisEvent.keyCode == 13)
{
    document.getElementById("#{id:searchButton}").click();
}

(代码添加到searchButton的onclick)


window.location.href = "test.xsp?search=" + document.getElementById("#{id:searchField}").value;

我在IE和Firefox中测试过它们都有问题。我创建了一个示例HTML文件,它正常工作。这是XPages的错误还是我在这里遗漏了什么?

I tested it in IE and Firefox, both have problems. I created a sample HTML file and it worked correctly. Is this a bug of XPages or am I missing something here?

推荐答案

在'.click()'之后添加:

Add this after your '.click()':

       thisEvent.preventDefault();
       thisEvent.stopPropagation(); 

应解决问题; - )

It should solve the problem ;-)

这篇关于XPages - onkeypress事件未正确触发点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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