在复选框点击中获取Fexigrid中的表行ID值?

时间:2013-03-13 23:44:02

标签: javascript jquery html css flexigrid

我正在开发FlexiGrid,并且几乎没有脚本问题。我已经成功创建了FlexiGrid并添加了复选框。在复选框上单击,我想选择所需的行。在单击任何行时,它会在<tr id="row101" class="trSelected">中设置class ='trSelected'。我已经尝试了一些脚本来设置它复选框单击,但不起作用。请让我知道如何解决此问题。

<script type="text/javascript"> 
function checkedCall() {
 if( $('#checkNote').is(':checked')){
   //$("#tblflex > tr:first").addClass("trSelected");
   //$(this).parents('tr:first').addClass('trSelected');
   alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
 }else{
  alert('NOTSelected');
  //$("#tblflex > tr:first").removeClass("trSelected");
  //$(this).parents('tr:first').removeClass('trSelected');
 }
}

HTML代码:

<table id="tblflex" class="flexCLS" style="display: table;" border="0">
 <tbody>
  <tr id="row101">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote" onclick="checkedCall();">
    </div>
   </td>
 </tr>
  <tr id="row187">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote" onclick="checkedCall();">
   </div>
 </td>
</tr>

   

谢谢!

1 个答案:

答案 0 :(得分:0)

问题是您的所有复选框都具有相同的ID“checkNote”。

这是一个建议的解决方案

HTML

<table id="tblflex" class="flexCLS" style="display: table;" border="0">
 <tbody>
  <tr id="row101">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote101" onclick="checkedCall(this);">
    </div>
   </td>
 </tr>
  <tr id="row187">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote187" onclick="checkedCall(this);">
   </div>
 </td>
</tr>

和JS代码

<script type="text/javascript"> 
function checkedCall(this) {
 if( $(this).is(':checked')){
   //$("#tblflex > tr:first").addClass("trSelected");
   //$(this).parents('tr:first').addClass('trSelected');
   alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
 }else{
  alert('NOTSelected');
  //$("#tblflex > tr:first").removeClass("trSelected");
  //$(this).parents('tr:first').removeClass('trSelected');
 }
}