使用jquery禁用和启用下拉列表

Alm*_*lma 0 javascript jquery

如何在"编辑"中禁用"下拉",但在"创建用户"中启用.我在MVC视图中下拉,在jquery中创建和编辑用户.我已经尝试过这些,但没有在jquery中使用以下任何一个禁用它:

 $("#dropdown").prop("disabled", false);  

 $('#dropDownId').attr('disabled', true);

 $('#dropdown').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)

当我喜欢这个时,在我的MVC中:

  <select id="organization" class="create-user-select-half" disabled>
Run Code Online (Sandbox Code Playgroud)

它使它禁用但我不能再次在jquery中启用它.

Tim*_*O84 6

你必须设置

$("#dropdown").prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)

用于禁用控件.要再次启用它,您必须致电:

$("#dropdown").prop('disabled', false);
Run Code Online (Sandbox Code Playgroud)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="organization" class="create-user-select-half" disabled>
  <option value="1">dsdsd</option>
  </select>

<button onclick="$('#organization').prop('disabled', false)">Enable</button>
<button onclick="$('#organization').prop('disabled',true)">Disable</button>
Run Code Online (Sandbox Code Playgroud)