简体   繁体   English

将输入框动态添加到表单中?

[英]Dynamically add input boxes into form?

What I am trying to do is very similar to this question: 我正在尝试做的事情与这个问题非常相似:
Using jQuery to dynamically add form fields (or fieldsets) based on a dropdown box value 使用jQuery根据下拉框值动态添加表单字段(或字段集)

Specifically, I want to use a drop down box value to add that number of input boxes to a fieldset. 具体来说,我想使用下拉框值将输入框的数量添加到字段集中。

I do not know jQuery so the answer I am linking to hasn't answered my question, I would like to know how to do this in JavaScript? 我不知道jQuery,所以我链接到的答案没有回答我的问题,我想知道如何在JavaScript中执行此操作?

There are lots of instructions on how to use JQuery. 关于如何使用JQuery有很多说明。 I suggest that you go to http://docs.jquery.com to learn it rather than looking here for a specific answer to your question. 我建议您去http://docs.jquery.com进行学习,而不要在这里寻找问题的具体答案。 Spending the time to figure it out for yourself will be far more useful than a copy-paste answer. 花时间自己解决这个问题比复制粘贴的答案有用得多。

You'll follow some basic steps. 您将遵循一些基本步骤。 Tackle each one individually. 分别解决每个问题。

  • Read the value from the drop-down when it changes. 更改时,从下拉菜单中读取值。
  • Find the element to contain the new input boxes. 查找包含新输入框的元素。
  • Loop through the number of values 遍历值的数量
  • Insert the appropriate HTML for each loop iteration. 为每个循环迭代插入适当的HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM