簡體   English   中英

單擊復選框獲取Fexigrid中的表行ID值?

[英]Get the table row id value in Fexigrid on checkbox click?

我正在研究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');
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM