簡體   English   中英

html表中具有多行的復選框(iswitch)

[英]Checkbox (iswitch) in html table with multiple rows

這是HTML代碼(表代碼的一部分):

<td class="center">
    <?php if ($row['datum_afhaling']) { ?>
            <input class="active iswitch iswitch-success" type="checkbox" cdid="<?php echo $row['cdid']; ?>" value="<?php echo $row['id']; ?>" checked></td>
        <?php } else { ?>
            <input class="active iswitch iswitch-success" type="checkbox" cdid="<?php echo $row['cdid']; ?>" value="<?php echo $row['id']; ?>"></td>
    <?php } ?>
</td>

和javascript代碼:

$("input.active").click(function() {

    var check_active = $(this).is(':checked') ? 'ja' : 'nee';
    var check_id = $(this).attr('value');
    var cd_id = $(this).attr('cdid');

    $.ajax({
        type: "POST",
        url: "cudi-afhalen-status-ajax.php",
        data: {id: check_id, active: check_active, cdid: cd_id},
        success: function(){

            alert ('id: '+check_id+' & active: '+check_active+' & cdid: '+cd_id);
            location.href='cudi-bestellingen-overzicht.php';
        }
    });
    return true;
});

如果將復選框切換到另一側,則會創建一個帶有一些參數的警報框。 到目前為止,效果很好,但是代碼相互之間給了我15個alertboxen,因為我的表中有15行。 所有警報框中的值(參數)相同。 我切換了1個checkbox-iswitch,所以我只有1個帶參數的Alertbox,而不是其他14個。 我不知道為什么會這樣?

編輯我發現這里的代碼出了什么問題。 javascript代碼在我的while循環中。 所以我在循環外替換了它,一切正常。

試試下面的代碼

$("input.active").click(function() {

var check_active = $(this).is(':checked') ? 'ja' : 'nee';
var check_id = $(this).attr('value');
var cd_id = $(this).attr('cdid');
var al = 1;
$.ajax({
    type: "POST",
    url: "cudi-afhalen-status-ajax.php",
    data: {id: check_id, active: check_active, cdid: cd_id},
    success: function(){
        if(al==1){
        alert ('id: '+check_id+' & active: '+check_active+' & cdid: '+cd_id);
         al=0;
         }

          location.href='cudi-bestellingen-overzicht.php';
    }
});
return true;
});

暫無
暫無

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

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