基于类jQuery提交表行

时间:2015-04-14 14:16:59

标签: javascript jquery model-view-controller

我正在使用jQuery.DataTables plugin。我用它来更改点击的表行类,使它们看起来像选择"。然后,我希望能够将这些行中的数据汇总或发送回MVC应用程序。我尝试将行添加到数组中,因为它们被点击但是我无法使inArray函数起作用所以也许在点击按钮时发送class='selected'行会更容易?

$('#classes tbody').on('click', 'tr', function () {
    $(this).toggleClass('selected'); 
});

$('#WatchButton').click(function () {
    //Not sure how to send the 'selected' rows        
});

表格示例:

<table id="classes" class="display" cellspacing="0" width="100%">
<thead>
    <tr>
            <th>OpenClosed</th>
            <th>Section</th>
            <th>CRN</th>
            <th>Credit Hours</th>
            <th>Part/Term</th>
            <th>Capacity</th>
            <th>Enrolled</th>
            <th>Seats Available</th>
            <th>Waitlist Capacity</th>
            <th>Waitlist Count</th>
            <th>Waitlist Availability</th>
            <th>Campus</th>
            <th>Method</th>
            <th>Location</th>
            <th>Time</th>
            <th>Start Date</th>
            <th>End Date</th>
            <th>Instructor</th>
            <th>Days</th>
    </tr>
</thead>
<tbody>
        <tr>
                <td><IMG SRC='https://owlexpress.kennesaw.edu/stugifs/open.gif'></td>
                <td>MATH 0989/01 - Foundations of College Algebra</td>
                <td>80637</td>
                <td>       3.000</td>
                <td>Full Term</td>
                <td>15</td>
                <td>5</td>
                <td>10</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>Kennesaw Campus</td>
                <td>Classroom - 100%</td>
                <td>LibraryRoom 461</td>
                <td>12:30 pm - 1:45 pmLecture</td>
                <td>Aug 17, 2015</td>
                <td>Dec 14, 2015</td>
                <td>Bhupinder   Naidu (P)</td>
                <td></td>
        </tr>
        <tr>
                <td><IMG SRC='https://owlexpress.kennesaw.edu/stugifs/open.gif'></td>
                <td>MATH 0989/02 - Foundations of College Algebra</td>
                <td>80639</td>
                <td>       3.000</td>
                <td>Full Term</td>
                <td>15</td>
                <td>0</td>
                <td>15</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>Kennesaw Campus</td>
                <td>Classroom - 100%</td>
                <td>LibraryRoom 430</td>
                <td>6:30 pm - 7:45 pmLecture</td>
                <td>Aug 17, 2015</td>
                <td>Dec 14, 2015</td>
                <td>Bonnie W  Sellers (P)</td>
                <td></td>
        </tr>
        <tr>
                <td><IMG SRC='https://owlexpress.kennesaw.edu/stugifs/open.gif'></td>
                <td>MATH 0989/03 - Foundations of College Algebra</td>
                <td>85687</td>
                <td>       3.000</td>
                <td>Full Term</td>
                <td>15</td>
                <td>3</td>
                <td>12</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>Kennesaw Campus</td>
                <td>Classroom - 100%</td>
                <td>LibraryRoom 462</td>
                <td>9:30 am - 10:45 amLecture</td>
                <td>Aug 17, 2015</td>
                <td>Dec 14, 2015</td>
                <td>Bhupinder   Naidu (P)</td>
                <td></td>
        </tr>
</tbody>
</table>

1 个答案:

答案 0 :(得分:0)

我猜你是在问如何获取所选行的数组,是吗? :

$('#WatchButton').click(function () {
   var selectedrows = $('tr.selected');
});