簡體   English   中英

有特定值時,禁用加載時表上的復選框

[英]Disable checkbox on table on load when there is specific value

我想檢查頁面加載時的表行值。

表示例:

名稱 || 狀態 ||

約翰|| 通過|| [](復選框)

克里斯|| 失敗|| [](復選框)

狀態為“失敗”時,我要禁用該復選框。

現在,我正在使用此jQuery

<script>
$(document).ready(function() {  

    if(getElementsByClassName('paket_ava').value=='kosong'))
    {  
        document.getElementById("checkboxx").disabled=true;
    } 
});
</script>

這是我的PHP表代碼

<tr>
    <td><?php echo $paket['id_paket'];?></td>                                   
    <td><?php echo $paket['nama_paket'];?></td>     
    <td><?php echo $paket['keterangan_paket'];?></td>
    <td><?php echo $paket['harga'];?></td>
    <td><img src='<?php echo $paket['gambar_paket']?>' width='120' height='120'></td>
    <td  class="paket_ava"><?php echo $paket['ketersediaan_paket'];?></td>
    // class on the table data
    <td><?php echo $paket['status_harian_paket'];?></td>
    <td><input type="checkbox" name="chkDel[]" id="checkboxx" class="aku" value="<?=$paket["id_paket"];?>"></td>
    <?php
         echo ("<td><a href='edit_data_paket.php?id_paket=$paket[id_paket]'>Edit</a></td>");        
    ?>
</tr>

上面的代碼不起作用,但是如果我更改為:

if(getElementsByClassId('paket_ava').value=='kosong')) 
        {  
            document.getElementById("checkboxx").disabled=true;
        } 

(當然,我將表中的類更改為ID)

當頁面加載時,其行為奇怪,並且第一個數據上的復選框被禁用。

如何正確執行此操作?

嘗試如下....它將為您提供幫助...

小提琴示例: http : //jsfiddle.net/68wbx/126/

假設您的HTML表格如下所示:

HTML:

<table id="datapaket" border="1">
    <tr>
        <th>Name</th><th>Status</th><th>Set</th>
    </tr>
    <tr>
        <td>John</td><td class="paket_ava">Pass</td>
        <td><input type="checkbox" name="chkDel[]" id="checkboxx" class="aku" value='sam'/></td>
     </tr>
    <tr>
        <td>Chris</td>
        <td class="paket_ava">Fail</td>
        <td><input type="checkbox" name="chkDel[]" id="checkboxx" class="aku" value='sam'/></td>
      </tr>
</table>

並嘗試以下Jquery:

$(document).ready(function() {      
    $('#datapaket tr').each(function() {    //Looping Every Table Row
      //Get the TD Value that have Classname ".paket_ava"
      var str = $(this).find('.paket_ava').html(); 
      if(typeof str !== 'undefined'){
        if (str.indexOf("Fail") >= 0)
        $(this).find('td:nth-child(3) input:checkbox').attr("disabled", true);
      };
    });
});

遍歷具有類'paket_ava'的每個元素,並在其中進行操作。 喜歡

 $('.paket_ava').each(function(i, obj) {
// your stuff...
});

參考: jQuery遍歷具有相同類的元素

暫無
暫無

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

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