2015-04-14 42 views
0

我正在使用jQuery.DataTables plugin。我用它来改变被点击的表格行的类别,所以他们看起来“选择”。然后,我希望能够将这些行中的数据归入或发送回MVC应用程序。我尝试将行添加到数组中,因为它们被点击,但我无法使inArray函数正常工作,所以单击按钮时发送class='selected'行可能会更容易?表根据类jQuery提交表格行

$('#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> 

回答

0

我猜你是问如何获得所选行的阵列,是这样吗? :

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

就是这样,谢谢!我对javascript不是很熟悉。 – Jrow