Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Seam/JSF表单提交触发按钮onclick事件_Java_Html_Firefox_Jsf_Seam - Fatal编程技术网

Java Seam/JSF表单提交触发按钮onclick事件

Java Seam/JSF表单提交触发按钮onclick事件,java,html,firefox,jsf,seam,Java,Html,Firefox,Jsf,Seam,我有一个带有查询生成器的搜索表单。生成器由一个按钮激活。像这样的 <h:form id="search_form"> <h:outputLabel for="expression" value="Expression"/> <h:inputText id="expression" required="true" value="#{searcher.expression}"/> <button onclick="openBuilder(); r

我有一个带有查询生成器的搜索表单。生成器由一个按钮激活。像这样的

<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的表单中既有
又有
。如果用户在表达式字段中输入字符串并按enter键而不是单击submit按钮,则当预期行为是提交搜索时,将显示查询生成器。给出了什么?

假定HTML表单中的按钮用于提交表单。将button更改为input type=“button”,这样应该可以修复它


或者,将type=“button”添加到按钮元素。

首先,为搜索按钮提供一个ID。 然后,在textbox上,您可以使用如下(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();
        }
    }

我希望能为您提供帮助。

如果表单中只有一个输入字段,许多浏览器会在按下enter键时自动提交表单

试一试

  • 添加另一个输入字段。通过设置样式将其隐藏,使其不可见。(例如,
  • 在JavaScript事件处理程序中阻止enter键表单提交行为(例如,或)。更好的是,使用GUI工具包(例如,GWT)对此提供帮助