javascript复选框启用/禁用

2022-01-16 00:00:00 checkbox listbox javascript html

好吧,这很烦人,而且可能很简单.我想用禁用的复选框开始我的网页,然后选择列表框中的特定行以启用这些框.所以我把这个放在onload方法中

Ok this is very anoying, and it is probably very simple. I want to start my web page with disabled checkboxes, and after particlar line in listbox is selected to enable those boxes. So I put this in onload method

onload = function () {
   for (i = 0; i < document.frmMain.checkgroup.length; i++){
        document.frmMain.checkgroup[i].disabled = true ;
   }
}

它以禁用框开始我的页面,现在我想启用它们

it start my page with disabled boxes, now i want do enable them

function enableCheckboxes(){
    if (document.frmMain.Vrste[document.frmMain.Vrste.selectedIndex].value == "Sendvici i Rostilj"){
        for(i=0;i<document.frmMain.checkgroup.length;i++){
       document.frmMain.checkgroup[i].enabled = true;

        }
    }
}

它进入 for 循环,但它从不启用这些复选框.我不知道为什么.

it goes in to the for loop, but it never enable those checkboxes. I cannot figure it why.

这是 html 部分,我在这里调用 enablecheckbox 函数:

and this is html part, where i call enablecheckbox function:

<select name="Vrste" onChange="PopulatePodvrste(); enableCheckboxes();"  size="8">
    <option value="Pica">Pica</option>
    <option value="Barbarina domaca trpeza">Barbarina domaca trpeza</option>
    <option value="Slana Palacinka">Slana Palacinka</option>
    <option value="Slatka Palacinka">Slatka Palacinka</option>
    <option value="Sendvici i Rostilj">Rostilj i sendvici</option>
    <option value="Dobro jutro sa Barbarom">Dobro jutro sa Barbarom</option>
    <option value="Chicken Meni">Chicken Meni</option>
    <option value="Posebna Ponuda">Posebna Ponuda</option>
    <option value="Salate">Salate</option>
</select>

最后是实际的复选框:

<input type="checkbox" name="checkgroup" >Susam</input><br>
<input type="checkbox" name="checkgroup" >Cili</input><br>
<input type="checkbox" name="checkgroup" >Tartar</input><br>
<input type="checkbox" name="checkgroup" >Urnebes</input><br>
<input type="checkbox" name="checkgroup" >Krastavac</input>

推荐答案

试试吧:

    document.frmMain.checkgroup[i].disabled = false ;

相关文章