这是我想要获取表select
中每个td
元素值的代码。
SCRIPT:
var itemno = 1;
$('.IAtable').append('
<tr>
<td>
<center><div class="form-inline">
<select id="month'+itemno+'" class="form-control square" name="month'+itemno+'"></select> -
<select id="days'+itemno+'" class="form-control square" name="days'+itemno+'"></select> -
<select id="year'+itemno+'" class="form-control square" name="year'+itemno+'"></select>
</div></center>
</td>
</tr>');
//populate month data
for (i = 1; i <= 12; i++)
{
$('#month'+itemno).append($('<option />').val(i).html(i));
}
//populate day data
for (i = 1; i <= 31; i++)
{
$('#days'+itemno).append($('<option />').val(i).html(i));
}
//populate year data
var start = (new Date).getFullYear();
for (i = start; i <= start+50; i++)
{
$('#year'+itemno).append($('<option />').val(i).html(i));
}
var TableData = new Array();
$('.IAtable tr').each(function(row, tr){
TableData[row]={
, "Month" : $(tr).find('td:eq(5) #month'+itemno+' option:selected').val()
, "Day" : $(tr).find('td:eq(5) #days'+itemno+' option:selected').val()
, "Year" : $(tr).find('td:eq(5) #year'+itemno+'option:selected').val()
}
itemno++;
TableData = $.toJSON(TableData);
alert(TableData['Month']+'-'+TableData['Day']+'-'+TableData['Year']);
alert
没有显示任何价值。