【问题标题】:Changing post parameters of form on submit without it being visible to the user在提交时更改表单的 post 参数而不对用户可见
【发布时间】:2016-01-18 18:20:31
【问题描述】:

我有以下代码:

   <h:form >
       <h:inputText  value="#{bean.property}"/><br/>
       <h:commandButton
           value="Send"
           action="#{bean.action}"/>
   </h:form>

当有人单击按钮而用户不可见时,我如何(不使用 jQuery)更改 post 表单中 inputText 的属性值?假设我知道生成的 html 中的 inputTexts 名称,例如

<input type="text" name="inputName" />

我的尝试是

   document.forms['formName'].onsubmit = function(){
       var txt = document.getElementsByName("inputName")[0];
       txt.value = "changed"
       documents.forms['formName'].submit();
   }

但这会改变 inputText 中的内容,并且清晰可见。

【问题讨论】:

    标签: javascript html jsf


    【解决方案1】:

    在表单中添加一个隐藏的输入字段。在 OnSubmit 事件处理程序中,将该字段设置为您想要的任何值。让后端忽略对用户可见的字段,只使用隐藏的字段(您可以通过命名字段的方式来实现)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多