javascript - 单击复选框时获取 Fexigrid 中的表行 ID 值?

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

谢谢!

最佳答案

问题是您的所有复选框都具有相同的 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');
 }
}

关于javascript - 单击复选框时获取 Fexigrid 中的表行 ID 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15398648/

相关文章:

javascript - 带有 AngularJS 的 ChartJS - Canvas 不会显示任何内容

javascript - GM_openInTab(或任何其他 GM_ 函数)未定义?

javascript - 如何制作该标签的另一图像(通过拖动),该图像不会影响原始图像

PHP/CSS 不能让元素放在 table 上?

javascript - 无法使用 JavaScript 选择最接近的 h2 元素

html - 当我使用 :hover in css (No javascript) 时元素向上移动

javascript - Gulp.js 不会重新加载纯 CSS

javascript - 链接在新页面加载,而不是 iframe

javascript - jquery "hasClass()"不工作?

javascript - jQuery 函数 Mouseenter 和 Mouseleave 不工作