如何启用禁用的选择选项?

时间:2013-12-03 17:13:04

标签: javascript php attributes null onchange

我有一个由JavaScript生成的下拉列表。基本上,当进行选择时,此下拉列表会随值(在onchange事件上)更改,如果返回的值为null或空白,则应禁用它,这可以正常工作,但是当更改选择并重新加载值时,甚至值非空白是否被禁用?

以下是代码,我在这个简单的循环中说的是:如果值不为空,则保持值为else,如果为空,则禁用这些值:

   echo "\t\tfor(index=1; index < $maxfield1rows; index++)\n";
       echo "\t\t{\n";
       echo "\t\tif(document.pickDivision.field1.options[index].value !='')\n";
           echo "\t\t{\n";
           echo "\t\tdocument.pickDivision.field1.options[index].enabled=true\n"; 
           echo "\t\t}\n\n";
           echo "\t\telse\n";
              echo "\t\t{\n";
              echo "\t\t(document.pickDivision.field1.options[index].disabled=true)\n"; 
       echo "\t\t}\n\n";      
    echo "\t\t}\n\n";

如果可以,请帮忙。

1 个答案:

答案 0 :(得分:0)

使用disabled = false;

echo "\t\tfor(index=1; index < $maxfield1rows; index++)\n";
       echo "\t\t{\n";
       echo "\t\tif(document.pickDivision.field1.options[index].value !='')\n";
           echo "\t\t{\n";
           echo "\t\tdocument.pickDivision.field1.options[index].disabled=false\n"; 
           echo "\t\t}\n\n";
           echo "\t\telse\n";
              echo "\t\t{\n";
              echo "\t\t(document.pickDivision.field1.options[index].disabled=true)\n"; 
       echo "\t\t}\n\n";      
    echo "\t\t}\n\n";