我使用 Xpages 自定义控件创建了一个搜索字段 (id:searchField) 和一个搜索按钮 (id:searchButton)。我在搜索字段上添加了一个 onkeypress 事件,这样它将触发对 searchButton 的单击。然后,searchButton 将重新加载页面,但使用来自搜索字段的 url 参数。问题是页面重新加载但搜索参数未添加到 URL当我在搜索字段中按 ENTER 键时,但当我按下 searchButton 时工作正常。这是我使用的代码:
(代码添加到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 的错误还是我在这里遗漏了一些东西?
在“.click()”之后添加以下内容:
thisEvent.preventDefault();
thisEvent.stopPropagation();
它应该可以解决问题;-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)