Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中选中复选框时禁用和/或启用按钮_Javascript_Html - Fatal编程技术网

在javascript中选中复选框时禁用和/或启用按钮

在javascript中选中复选框时禁用和/或启用按钮,javascript,html,Javascript,Html,选中复选框时如何禁用或启用按钮。此复选框位于数据循环中 所以有很多复选框,我用类名得到复选框 <input type="checkbox" name='checked[]' class='check' onclick="aktifkan()" id='checked' value="<?= $data['gedung']; ?>"> <!-- [] di pilih[] untuk menampun

选中复选框时如何禁用或启用按钮。此复选框位于数据循环中 所以有很多复选框,我用类名得到复选框

<input type="checkbox"  name='checked[]' class='check' onclick="aktifkan()"  id='checked'  value="<?= $data['gedung'];  ?>"> <!-- [] di pilih[] untuk menampung multiple checkbox -->

以下是您想要的东西:

const cekbox=document.getElementsByClassName('check');
const editt=document.getElementById('edit');
const hapuss=document.getElementById('hapus');
函数aktifkan(){
设j=cekbox.length;
让发现=错误;
对于(设i=0;(i}
您的预期输出是什么?你的代码看起来很好,并且按照这个问题的标题工作。mozila firefox Uncaught TypeError:cekbox[i]未定义aktifkan如果单击你的代码可以正常工作,只需使用
for(i=0;i
而不是
for(i=0;i请允许您的问题包含有关错误消息的重要信息。因此,aktifkan()只适用于最后一个复选框。我希望当选中任何复选框时,按钮将启用,如果没有选中任何复选框,则按钮将禁用。以下是mozila firefox-mozila firefox Uncaught TypeError中的错误:cekbox[i]未定义的aktifkan localhost:81/mitra_medika/poliknik/data.php?hal=1:272单击localhost:81/mitra_medika/poliknik/data.php?hal=1:1
<button class="btn btn-succes btn-sm pull-right mb-2" disabled id="edit" onclick='edit()'>Edit</button>
<button class="btn btn-danger btn-sm pull-right mb-2" disabled id="hapus" onclick='hapus()'>delet</button>         

const cekbox     = document.getElementsByClassName('check');
const editt      = document.getElementById('edit');
const hapuss     = document.getElementById('hapus');
function aktifkan (){
    var i ;
    var j = cekbox.length;
    for( i = 0 ; i<= j ; i++){
        // if checkbox.checked = true; theb button.disabled = false
        if (cekbox[i].checked == true){
            editt.disabled = false;
            hapuss.disabled = false ;
        }
        // if checkbox.checke = false; then button.disabled = true
        else{
            editt.disabled = true;
            hapuss.disabled = true;
        }

    }            

}