簡體   English   中英

禁用無法使用Chrome瀏覽器

[英]disable is not working chrome browser

在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>

請提供解決此問題的任何解決方案...

使用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);
...

使用setattribute代替

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

嘗試:

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

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

暫無
暫無

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

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