我如何添加一行到HTML表单
How can I add a row to an HTML form?
我正在制作一个简单的应用程序,其中有一系列下拉框或文本框。一旦用户填写了这些内容,结果字符串就会被连接起来并显示给用户。现在我需要一个简单的函数,用户可以按下"+"按钮并添加一行。理想情况下,我需要复制上面的行(包括输入)。例如:
dropdown
textbox
textbox
dropdown
concatenated string
我如何简单地复制上面的行(减去连接的字符串),包括用户输入的内容。如果现在简单地添加上面的行就好了。我用的是JavaScript…下面是一个表单的代码,例如:
<form action="">
<input type="text" id="site" value="Site" title="Site" onfocus="clickclear(this, 'Site')" onblur="clickrecall(this,'Site')" />
<input type="text" id="placementdesc" value="Placement description" title="Placement description" onfocus="clickclear(this, 'Placement description')" onblur="clickrecall(this,'Placement description')" />
<input type="text" id="placementtype" value="Placement Type" title="Placement Type" onfocus="clickclear(this, 'Placement Type')" onblur="clickrecall(this,'Placement Type')" />
<input type="text" id="size" value="Size" title="Size" onfocus="clickclear(this, 'Size')" onblur="clickrecall(this,'Size')" />
<input type="text" id="pricing" value="Pricing" title="Pricing" onfocus="clickclear(this, 'Pricing')" onblur="clickrecall(this,'Pricing')" />
<select id="servetype" title="Serve Type">
<option>STD – Standard trafficking type</option>
<option>SSV – Site-served</option>
<option>PIX – Pixel</option>
<option>CCD – Click command</option>
<option>PCC – Pixel and Click command</option>
<option>RMV – Rich Media Video</option>
<option>RME – Rich Media Expand</option>
<option>RMO – Rich Media Other</option>
</select>
</form>
这是简单的还是我需要使用DOM和使用createElement
等?如果在表格中完成会更容易吗?
只是为了清楚,我试图不使用JQuery…如果这样做更容易的话,我愿意改变。
在每个输入旁边添加加号按钮,并给它们一个类addRow
(例如)。
将函数映射到.addRow
的点击事件:
$(".addRow").click(function(){
$(this)
.prev("input") // select the previous input element
.clone() // clone said element
.appendTo("#formID"); // append the clone to the form
});
请记住,这也将克隆输入的现有值,因此您可能希望在附加它之前使用val()
清除克隆的值。
相关文章:
- 从 html 表中选择一行(突出显示)并在单击按钮时发送值
- html画布鼠标后的一行
- 当上一行/当前行被填充时,将新行添加到HTML表中
- Html-从数据库中删除一行
- 用 HTML 中的一行连接 2 张图像.姜戈模板
- 如何将动态颜色应用于与 HTML 表不同的每一行
- 从同一行中获取最接近复选框列的列的 html 值
- 使用 JavaScript 编辑 HTML 中的每一行
- 阻止浮动 HTML 元素下降到下一行
- 如何使用jQuery和Ajax将文本文件中的每一行加载到HTML列表中
- JQuery HTML 避免使用每个表中的第一行
- html表的xsl生成为每一行提供一个按钮
- 如何在嵌入php的html表中为每一行添加复选框,并在数据库(Postgresql)中更新其值
- 在不影响第一行的情况下,每隔一行缩进一个表.html/css/js/jQuery
- 如何使用jQuery根据某些条件获取HTML表的下一行
- 阻止一行html出现在谷歌搜索中
- 如何将值获取到一行html数据表中
- 在一个页面被呈现后,任何方式都可以去掉一行HTML代码
- 禁用最后一行html表复选框
- 为什么我不能删除每一行html的空白?