如何在td jquery中获取多个select的值

时间:2014-12-18 11:15:26

标签: jquery html-table append

这是我想要获取表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没有显示任何价值。

0 个答案:

没有答案