1

此代码在 chrome 中运行时无法禁用列表框...但它在 firefox 中工作...是否有任何通用脚本可以在所有浏览器中工作

<script>
    function fun()
    {
      //alert("welcome==>"+document.getElementById("geography").value);
         if(document.getElementById("geography").value!=0)
             {

             document.getElementById("country").disabled=true;
             document.getElementById("state").disabled=true;
             }
         else
             {
             document.getElementById("country").disabled=false;
             document.getElementById("state").disabled=false;
            }
             }
             }
    </script>
    </head>
    <body>
     <form name="example" action ="" method="get">
    <table>
    <tr><td>Geography</td> <td><select name="geography"  id="geography" 
    onchange="fun()">
    <option value="0">select</option>
    <option value="1">zone</option>
    <option value="2">state</option>
    <option value="3">city</option>
     </select></td></tr>
    </table>
    <table>
    <tr><td>country</td> <td><select name="country" id="country">
    <option value="0">select</option>
    <option value="1">india</option>
    <option value="2">china</option>
    <option value="3">pak</option>
    </select></td></tr>
    </table>
    <table>
    <tr><td>state</td> <td><select name="state" id="state">
    <option value="0">select</option>
    <option value="1">tamil</option>
    <option value="2">kerala</option>
    <option value="3">andra</option>
      </select></td></tr>
      </body>

请提供任何解决方案来解决这个问题......

4

3 回答 3

2

请改用setAttributeremoveAttribute

document.getElementById("country").setAttribute("disabled", "disabled");
document.getElementById("country").removeAttribute("disabled");

此外,辅助函数可能会稍微清理一下代码:

function setDisabledValue(id, value) {
  var elem = document.getElementById(id);
  if(value) elem.setAttribute("disabled", "disabled");
  else elem.removeAttribute("disabled");
}
setDisabledValue("country", true);
...
于 2013-09-13T12:05:52.500 回答
1

改用 setattribute

document.getElementById('country').setAttribute("disabled","disabled");
于 2013-09-13T12:06:21.487 回答
0

尝试:

document.getElementById("xxxx").setEnabled(true);

https://developers.google.com/apps-script/reference/ui/list-box#setEnabled(Boolean)

于 2013-09-13T12:06:27.707 回答