【问题标题】:Passing html form's Multiple input value from one input field to a JavaScript event function将 html 表单的多个输入值从一个输入字段传递给 JavaScript 事件函数
【发布时间】:2014-11-24 05:01:18
【问题描述】:

我想传递 html 表单的两个输入字段值并通过 JavaScript 将它们连接起来。当我发送一个值并且 concat 函数采用一个参数时,就可以了。但是当发送两个值并且 concat 函数采用两个参数时,它在 concat 函数中打印 > 并与 user_name 连接。我还需要从 user_name 字段传递标题。

   <form  "method="post"action="signup.php">
     <label>Name:</label>
        <input type="text" name="title" id="title" />
      <br/>
        <label>Email:;
       <input type="text" name="user_name" id="user_name" onkeyup="concat(this.value,title.value)" />
    </form>

【问题讨论】:

    标签: javascript c# html asp.net-mvc forms


    【解决方案1】:

    title.value 更改为document.getElementById("title").value

    【讨论】:

      【解决方案2】:

      使用这个。为表单提供一些名称和 id 名称并调用 concat 函数,如下所示。

        <form id="form1" name="form1" "method="post"action="signup.php">
           <label>Name:</label>
              <input type="text" name="title" id="title" />
            <br/>
              <label>Email:;
             <input type="text" name="user_name" id="user_name" onkeyup="concat(this.value, form1.title.value)" />
          </form>
      

      【讨论】:

      • 实际上我告诉给表单提供 name 和 id name。我这样做了。有效。谢谢@JuanMendes
      猜你喜欢
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 2017-03-21
      相关资源
      最近更新 更多