Seam / JSF表单提交触发按钮onclick事件
题
我有一个带有查询构建器的搜索表单。构建器由按钮激活。像这样的东西
<h:form id="search_form">
<h:outputLabel for="expression" value="Expression"/>
<h:inputText id="expression" required="true" value="#{searcher.expression}"/>
<button onclick="openBuilder(); return false;">Open Builder</button>
<h:commandButton value="Search" action="#{searcher.search}"/>
</h:form>
结果是HTML在表单中同时包含<button/>
和<input type="submit"/>
。如果用户在表达式字段中输入字符串并按Enter键而不是单击“提交”按钮,则在预期行为是提交搜索时,将显示查询构建器。是什么给了什么?
解决方案
假定HTML表单中的按钮用于提交表单。更改按钮以输入type = <!> quot; button <!> quot;那应该解决它。
或者,添加type = <!> quot; button <!> quot;到按钮元素。
其他提示
首先,为“搜索”按钮提供ID。 然后,在文本框上,您可以使用(javascript)函数拦截客户端事件 onkeydown :
function KeyDownHandler(event)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified button
document.getElementById('searchButtonId').click();
}
}
我好好帮助你。
不隶属于 StackOverflow