我怎样才能动态地添加输入字段到表单? [英] How can I dynamically add input fields to a form?

查看:92
本文介绍了我怎样才能动态地添加输入字段到表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并不是一个网络程序员,但我创建了一个简单的网络应用程序,它具有一个用户可以输入一系列点(x,y,z)的形式,但我不知道有多少用户将要进入。我不想猜测可能的最大值(100可能?),并将100个字段放在表单上,​​因为它看起来很丑。当用户输入数据而无需联系服务器时,添加更多字段(或取消隐藏字段)的最简单方法是什么。

I'm not much of a web programmer, but I'm creating a simple web app that has a form where the user can enter a series of points (x,y,z) but I don't know how many the user is going to enter. I don't want to guess the probable maximum (100 maybe?) and put 100 fields on the form because it would look ugly. What's the easiest way to add more fields (or unhide fields) as the user enters data without contacting the server.

目前我只是使用html& php,但我假设要做到这一点,我需要javascript?

Currently I'm just using html & php, but I assume to do this I'll need javascript?

目前我的代码看起来像这样,当用户输入数据时,我想要另一行出现。 / p>

Currently my code looks like this, as the user enters data, I want another row to appear.

<form action="edit.php" method="post"> 
  <table border=1> 
    <tr> 
      <td> 
      <td>X
      <td>Y
      <td>Z
    </tr> 
    <tr> 
      <td>1</td> 
      <td><input type=text name=x1 size=10 value="0.4318"></td> 
      <td><input type=text name=y1 size=10 value="0.0000"></td> 
      <td><input type=text name=z1 size=10 value="0.1842"></td> 
    </tr> 
    <tr> 
      <td>2</td> 
      <td><input type=text name=x2 size=10 value="0.4318"></td> 
      <td><input type=text name=y2 size=10 value="0.0000"></td> 
      <td><input type=text name=z2 size=10 value="-0.1842"></td> 
    </tr> 
    <tr> 
      <td>3</td> 
      <td><input type=text name=x3 size=10 value="-0.3556"></td> 
      <td><input type=text name=y3 size=10 value="0.0000"></td> 
      <td><input type=text name=z3 size=10 value="0.1636"></td> 
    </tr> 
    ... I want more to appear here...
  </table> 
  <button name="submit" value="submit" type="submit">Save</button> 
</form> 

任何想法都是最简单的方法吗?谢谢...

Any idea the easiest way? Thanks...

推荐答案

我会使用jQuery和追加新的输入。

I would use jQuery and append the new inputs.

这篇关于我怎样才能动态地添加输入字段到表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆