Html 如何禁用html中的整个下拉控件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1227212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:28:08  来源:igfitidea点击:

how to disable the entire dropdown control in html

htmldrop-down-menu

提问by leora

i see there is a disabled property on a specific item in the dropdown list but is there an enabled property on the whole html dropdown itself?

我看到下拉列表中的特定项目有一个禁用的属性,但是整个 html 下拉列表本身是否有一个启用的属性?

any suggestions?

有什么建议?

回答by Joey

According to the HTML 4 speca selectelement has a disabledattribute.

根据HTML 4 规范select元素具有disabled属性。

So

所以

<select disabled>
  <option>Something</option>
</select>

should work

应该管用

回答by Travis Heeter

disabled="disabled"

This will disable a value within the combo box (it will still show up, but it will not have the ability to be selected):

这将禁用组合框中的一个值(它仍然会显示,但不能被选中):

<select>
  <option disabled="disabled" value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

This will disable the whole combo box:

这将禁用整个组合框:

<select disabled="disabled">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

回答by Posto

may this will help

可能会有所帮助

is same as :

是一样的:

<html>
    <head>
       <script type="text/javascript">
          function makeDisable(){
          var x=document.getElementById("mySelect")
          x.disabled=true
          }
         function makeEnable(){
             var x=document.getElementById("mySelect")
              x.disabled=false
         }</script></head><body><form>
        <select id="mySelect"><option>Apple</option><option>Banana</option>
        <option>Orange</option>
        </select>
        <input type="button" onclick="makeDisable()" value="Disable list">
        <input type="button" onclick="makeEnable()" value="Enable list">
        </form>
        </body>
       </html>