简体   繁体   English

输入框帮助JavaScript / HTML

[英]Input Boxes Help JavaScript/HTML

MAJOR EDIT: Okay, so I am have to create a HTML page like this . 主要编辑:好的,所以我要创造一个像HTML页面这样 I have already done the HTML work but I need help in the Javascript section. 我已经完成了HTML工作,但是在Javascript部分需要帮助。 SO there are 2 parts of this - first to create additional textboxes when + is clicked, which I have already done 所以有两个部分-首先在单击+时创建其他文本框,我已经完成了

 textBoxNum = 2 function addElement() { if (textBoxNum => 2) { textBoxNum++; var objNewDiv = document.createElement('P'); objNewDiv.innerHTML = '<input type="text" placeholder = "Option ' + textBoxNum + '" id = "option' + textBoxNum + '" />'; document.getElementById('content').appendChild(objNewDiv); }; ;} 

The second part is to get information from the input boxes and save them into local storage in a variable, how do i do that considering the user could have clicked + and add more input boxes 第二部分是从输入框中获取信息并将其保存到变量中的本地存储中,考虑到用户可能单击+并添加了更多输入框,我该怎么做?

Actually you can't set the Name of variable in that way, instead you can 实际上,您不能以这种方式设置变量的名称,而是可以
1) create an array options = [], and keep use options[x] 1)创建一个数组options = [],并保留use options [x]
2) create inputs with certain class (for example class="option") and use 2)创建具有特定类的输入(例如class =“ option”)并使用
var options = document.getElementsByClassName("option");
which returns an array 返回一个数组
3) create inputs with certain name(for example name="option") and use 3)创建具有特定名称的输入(例如name =“ option”)并使用
var options = document.getElementsByName("option");
which returns an array 返回一个数组
4) get an array of all inputs on the page 4)获取页面上所有输入的数组
var options = document.getElementsByTagName('input');

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

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