我使用Xpages自定义控件创建了一个搜索字段(id:searchField)和一个搜索按钮(id:searchButton)。我在搜索字段中添加了onkeypress事件,以便触发点击到searchButton。然后,searchButton将重新加载页面,但使用来自搜索字段的url参数。问题是页面重新加载,但搜索参数没有被添加到网址,当我在搜索字段中按ENTER时,但按下searchButton时正常工作。下面是我使用的代码:(加入到searchField的onkeypress事件代码)XPages - onkeypress事件不触发点击正确
if (typeof thisEvent == 'undefined' && window.event) { thisEvent = window.event; } if (thisEvent.keyCode == 13) { document.getElementById("#{id:searchButton}").click(); }
(添加到搜索按钮的onclick代码)
window.location.href = "test.xsp?search=" + document.getElementById("#{id:searchField}").value;
我测试
在IE和Firefox中,都有问题。我创建了一个示例HTML文件,它工作正常。这是XPages的错误还是我在这里错过了一些东西?
是的,这是正确的 - 问题在于输入按键实际上是要将表单提交给服务器 - 页面重定向无法在此时发生。 – 2012-02-05 16:07:09