-1

我有这个代码:

$('#selectDay').bind('change', function () {
    $('.hours').show();
});

function fncCreateElement() {
    var mySpan = document.getElementById('mySpan');
    var myElement1 = document.createElement('select');
    myElement1.setAttribute('type', "text");
    myElement1.setAttribute('name', "fromTime");
    mySpan.appendChild(myElement1);
}

小提琴

选择日期后,我可以选择时间,直到时间,这有效。我需要的是,当我单击add date一个新行时,我可以在哪里选择新的一天(星期日 - 星期六),然后FROMUNTIL第一个已经工作的那样选择时间。

该表如下所示:

<table>
    <tr>
        <td>day</td>
        <td>From Hour</td>
        <td>Until Hour</td>
    </tr>
    <tr>
        <td>
            <select id="selectDay">
                <option value=''>Choose Time</option>
                <option value='1'>Sunday</option>
                <option value='2'>Monday</option>
                <option value='3'>Tuesday</option>
                <option value='4'>Wednesday</option>
                <option value='5'>Thursday</option>
                <option value='6'>Friday</option>
                <option value='7'>Saturday</option>
            </select>
        </td>
        <td>
            <div class="hours" style='display: none'>
                <select name="fromTime" class="mediumField">
                    <option value='6'>6</option>
                    <option value='7'>7</option>
                    <option value='8'>8</option>
                    <option value='9'>9</option>
                    <option value='10'>10</option>
                    <option value='11'>11</option>
                    <option value='12'>12</option>
                    <option value='13'>13</option>
                    <option value='14'>14</option>
                    <option value='15'>15</option>
                    <option value='16'>16</option>
                    <option value='17'>17</option>
                    <option value='18'>18</option>
                    <option value='19'>19</option>
                    <option value='20'>20</option>
                    <option value='21'>21</option>
                    <option value='22'>22</option>
                    <option value='23'>23</option>
                </select>
            </div>
        </td>
        <td>
            <div class="hours" style='display: none'>
                <select name="untilTime" class="mediumField">
                    <option value='6'>6</option>
                    <option value='7'>7</option>
                    <option value='8'>8</option>
                    <option value='9'>9</option>
                    <option value='10'>10</option>
                    <option value='11'>11</option>
                    <option value='12'>12</option>
                    <option value='13'>13</option>
                    <option value='14'>14</option>
                    <option value='15'>15</option>
                    <option value='16'>16</option>
                    <option value='17'>17</option>
                    <option value='18'>18</option>
                    <option value='19'>19</option>
                    <option value='20'>20</option>
                    <option value='21'>21</option>
                    <option value='22'>22</option>
                    <option value='23'>23</option>
                </select>
            </div>
        </td>
    </tr>
</table>
4

1 回答 1

1

尝试这个:

$(document).ready(function () {
    $(document).on('change','.selectDay', function () {
        $(this).closest('table').find('.hours').show();
    });
});
function fncCreateElement() {
    var new_table = $('table').eq(0).clone();
    $('table').last().after(new_table);
}

演示在这里

于 2013-09-14T21:55:12.707 回答