在每个表行中添加要选择的选项
Add option to select in each table row
我有一个表,每一行都有一些'select '。
我需要遍历每个表行,并将"选项"追加到数组中的选择。目前,只有表中的第一个'select'填充来自数组的数据。
我有以下HTML:
<table id="myTable">
<thead>
<tr>
<th>Code</th>
<th>Date</th>
<th>Description</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr class="RepeatingSection">
<td>
<select id="InputCode"></select>
</td>
<td>
<input type="date" name="Date" id="DateInput" required="required" />
</td>
<td>
<input type="text" id="DetailsInput" name="Details" size="35" required="required" />
</td>
<td>
<input type="number" id="percentageInput" max="100" value="100" />%</td>
</tr>
<tr class="RepeatingSection">
<td>
<select id="InputCode"></select>
</td>
<td>
<input type="date" name="Date" id="DateInput" required="required" />
</td>
<td>
<input type="text" id="DetailsInput" name="Details" size="35" required="required" />
</td>
<td>
<input type="number" id="percentageInput" max="100" value="100" />%</td>
</tr>
<tr class="RepeatingSection">
<td>
<select id="InputCode"></select>
</td>
<td>
<input type="date" name="Date" id="DateInput" required="required" />
</td>
<td>
<input type="text" id="DetailsInput" name="Details" size="35" required="required" />
</td>
<td>
<input type="number" id="percentageInput" max="100" value="100" />%</td>
</tr>
</tbody>
我目前有以下JavaScript:
var array;
var i;
var option;
var select;
array = [001, 002, 003, 004];
for (i = 0; i < array.length; i++) {
option = document.createElement("option");
option.value = array[i];
option.text = array[i];
select = document.getElementById("InputCode");
$('#myTable .RepeatingSection').each(function() {
$(this).find('#InputCode').each(function() {
select.appendChild(option);
})
})
select.appendChild(option);
}
Please also see my fiddle
任何帮助都会很感激。
试试下面的JavaScript代码:
var array;
var i;
var option;
array = [001, 002, 003, 004];
for (i = 0; i < array.length; i++) {
option = document.createElement("option");
option.value = array[i];
option.text = array[i];
$('#myTable .RepeatingSection').find( "select[id=InputCode]" ).append(option);
}
相关文章:
- CKeditor:更改对话框中的默认选择选项
- 如何在从多选下拉列表中选择选项值时动态生成文本框
- AngularJs列表ng单击以选择选项转换
- 使用基于文本的 Jquery 选择选项
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 在php和mysql中选择选项.一旦选择了选项,就列出我的sql数据库数据
- 选择选项时如何显示警报
- 使用php动态更改选择选项
- 选择“选择选项”时显示文本.怎么做
- LEAFLET地图和带有选择选项的标记-ANGULARjs
- 使用js将动态内容添加到选择选项列表中
- 用于使用javascript循环选择选项
- AngularJS-选择选项并在函数中使用它
- 禁用/启用基于单选/选择选项所选Javascript的文本框
- 如何使用jQuery隐藏与选择选项相关的选择选项列表
- 选择选项是添加或删除事件
- 使用jQuery向“选择选项”添加默认属性
- 构建HTML选择字段并使用JavaScript数组选择选项
- 带有动态选择选项的Firefox html5验证异常
- 只有当Angular从资源对象检索数据时,才选择选项元素