根据 class jQuery 提交 table 行

Submit table rows based on class jQuery

我正在使用 jQuery.DataTables plugin。我用它来更改 class of table 被单击的行,使它们看起来像“selected”。然后我希望能够将这些行中的数据汇总或发送回 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示例:

<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>

我猜您是在问如何获取选定行的数组,对吗? :

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