gpt4 book ai didi

javascript - 将附加行添加到数据库时如何插入附加信息

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:26 24 4
gpt4 key购买 nike

我的脚本能够在点击时添加额外的行。但是,我只能将第一行的内容存储在数据库中。我如何使其他附加行的内容也存储在数据库中?

<script>
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'time[]';
el.id = 'txtRow' + iteration;
el.size = 40;

el.onkeypress = keyPressTest;
cellRight.appendChild(el);

// select cell
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select');
sel.name = 'date[]';
sel.options[0] = new Option('Select a day', '');
sel.options[1] = new Option('Monday', 'Monday');
sel.options[2] = new Option('Tuesday', 'Tuesday');
sel.options[3] = new Option('Wednesday', 'Wednesday');
sel.options[4] = new Option('Thursday', 'Thursday');
sel.options[5] = new Option('Friday', 'Friday');
sel.options[6] = new Option('Saturday', 'Saturday');
sel.options[7] = new Option('Sunday', 'Sunday');
cellRightSel.appendChild(sel);
}
</script>

这是我的 html 代码的一部分:

<table border="1" id="tblSample" class="table table-bordered">
<tr>
<th colspan="5">Add Day and time
<input type="button" class="btn-danger addright" value="Add" onclick="addRowToTable();" />
<input type="button" class="btn-danger removeright" value="Remove" onclick="removeRowFromTable();" />
</th>
</tr>
<tr>
<td>1</td>
<td><input type="text" name="time[]" id="txtRow1" size="40" placeholder="e.g 8:00am - 3:00pm" onkeypress="keyPressTest(event, this);" /> </td>
<td>
<select name="date[]">
<option value="">Select a day</option>
</select>
</td>
</tr>
</table>

最佳答案

                $timeArr = $_POST['time'];
$dateArr = $_POST['date'];
//count the array
for ($i = 0; $i < count($timeArr); $i++) {
$datetimeoption = new datetimeoption();
$datetimeoption->prefer_day = $dateArr[$i];
$datetimeoption->prefer_time = $timeArr[$i];
//Insert data into database
$result = $datetimeoption->createdatetime();
}

关于javascript - 将附加行添加到数据库时如何插入附加信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com