我有下表,其中包含选择框,我想创建一个 JSON 字符串。我尝试了几个代码片段,但没有一个给我正确的输出。我想要的输出应该是:
id[0]: start time: 12:34;end time: 15:00
id[1]: start time: 18:14;end time: 18:17
ETC
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script language="Javascript">
function addRowEntry(tableID){
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[1].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
}
}
</script>
<table id="dynTable" name="dynTable" border=0 width="200px">
<thead>
<tr height="50" id="header">
<td class="datacell" align="center">Heure Start</td>
<td class="datacell" align="center">Min Start</td>
<td class="datacell" align="center">Heure End</td>
<td class="datacell" align="center">Min End</td>
<td class="datacell" ><input type="button" value="Ajouter" name="add" id="add" style="width:50px" onclick="addRowEntry('dynTable');"/></td>
</tr>
</thead>
<tbody>
<tr id="TimeSel">
<td class="datacell" >
<select id="openH" name="openH">
<option></option>
<?php
for ($i=0;$i<24;$i++) {
echo "<option id=$i>";
echo $i;
echo "</option>";
}
?>
</select>
</td>
<td class="datacell" >
<select id="openM" name="openM">
<option></option>
<?php
for ($i=0;$i<60;$i++) {
echo "<option id=$i>";
echo $i;
echo "</option>";
}
?>
</select>
</td>
<td class="datacell" >
<select name="closeH" id="closeH">
<option></option>
<?php
for ($i=0;$i<24;$i++) {
echo "<option id=$i>";
echo $i;
echo "</option>";
}
?>
</select>
</td>
<td class="datacell" >
<select name="closeM" id="closeM">
<option></option>
<?php
for ($i=0;$i<60;$i++) {
echo "<option id=$i>";
echo $i;
echo "</option>";
}
?>
</select>
</td>
</tbody>
</tr>
</table>
<input type="button" id="AddDateTime" name="AddDateTime" value="OK" onclick="tableToJson('dynTable');"></input>
编辑:我删除了包含文件。被认为是一些测试: