在UI中没有启用html select

html select does not enable in the UI

本文关键字:启用 html select UI      更新时间:2023-09-26

我有这个html代码

<td width="300px">
     <select id="Drpdwn_application2" 
             name="Drpdwn_application2" 
             ClientIDMode="static" 
             class="multiselect" 
             runat="server">
      </select>
</td>

我想知道为什么这个javascript不工作:

<script>
    // other codes
    document.getElementById("Drpdwn_application2").disabled = false;
</script>

作为替代,我也尝试了这个,但仍然不起作用,

var cbox = $("#Drpdwn_application2");
cbox.attr('disabled', 'disabled');
cbox.prop('disabled', false);

其他声明:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
    <script src="js/capability.js" type="text/javascript"></script>
    <script src="scripts/jquery-ui-1.10.3.js" type="text/javascript"></script>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="style/bootstrap/js/bootstrap-multiselect.js" type="text/javascript"></script>
编辑:

当我尝试使用alert检查属性disabled的值时,它显示正确的值,例如

alert(document.getElementById("Drpdwn_application2").disabled);
// return true/false
// which i think is working
// but the control in the UI is not updating

这里,

这是启用select

 $('#Drpdwn_application2').prop('disabled', false);

和禁用select,使用

 $('#Drpdwn_application2').prop('disabled', 'disabled');

Try This

Javascript

<script>
function disable() {
    document.getElementById("mySelect").disabled=true;
}
function enable() {
    document.getElementById("mySelect").disabled=false;
}
</script>
HTML

<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
<input type="button" onclick="disable()" value="Disable list">
<input type="button" onclick="enable()" value="Enable list">
演示