我正在这些文本框中向表中动态添加行,并且我有日期类型的文本框未动态添加。请用JS帮助我。除文本类型为DATE的文本框外,所有文本框都可以添加。
JS:
function addField (argument) {
var myTable = document.getElementById("myTable");
var currentRow = myTable.insertRow(-1);
var line_part_numberBox = document.createElement("input");
line_part_numberBox.setAttribute("name", "line_part_number[]");
var line_dateBox = document.createElement("input");
line_dateBox.setAttribute("name", "line_date[]");
var addRowBox = document.createElement("input");
addRowBox.setAttribute("type", "button");
addRowBox.setAttribute("value", "Add another line");
addRowBox.setAttribute("onclick", "addField();");
addRowBox.setAttribute("class", "button");
var currentCell = currentRow.insertCell(-1);
currentCell.appendChild(line_part_numberBox);
currentCell = currentRow.insertCell(-1);
currentCell.appendChild(line_dateBox);
}
刀片:
<table class="table table-striped" id="myTable">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
<th>action</th>
</tr>
</thead>
<tbody>
<tr>
<th>{{ Form::text('line_part_number[]', null , ['class' => 'form-control']) }}</th>
<th>{{ Form::date('line_date[]', null , ['class' => 'form-control']) }}</th>
<th><input type="button" class="button" value="Add another line" onclick="addField();"></th>
</tr>
</tbody>
</table>
答案 0 :(得分:1)
此代码将为您工作,我已经通过正常测试对其进行了测试。
var date_input = document.createElement("input");
date_input.setAttribute("type", "date");
currentCell.appendChild(date_input);