![](/img/trans.png)
[英]How to enable/disable drop down list box in HTML + Javascript/JQuery?
[英]Disable and Enable drop down using jquery
如何在編輯中禁用下拉菜單但在創建用戶中啟用。 我在 MVC 視圖中有下拉菜單,在 jquery 中有創建和編輯用戶。 我已經嘗試過這些,但沒有在 jquery 中使用任何這些來禁用它:
$("#dropdown").prop("disabled", false);
$('#dropDownId').attr('disabled', true);
$('#dropdown').prop('disabled', true);
在我的 MVC 中,當我有這樣的時候:
<select id="organization" class="create-user-select-half" disabled>
它使它被禁用,但我無法再次在 jquery 中啟用它。
你必須設置
$("#dropdown").prop('disabled', true);
用於禁用控件。 要再次啟用它,您必須調用:
$("#dropdown").prop('disabled', false);
<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>
您應該一起刪除該屬性以重新啟用下拉列表。
$('#dropdown').removeAttr('disabled')
要啟用下拉列表中的所有子元素:
for (var x = 0; x < $("#organization")[0].childElementCount; x++) { $('#organization')[0][x].disabled = false; }
禁用的項目不可點擊。 您可以在選擇標簽之外使用 div。
<div class="editable">
<select id="organization" class="create-user-select-half" disabled>
</div>
$(".editable").on("click", function () {
$('#organization').prop('disabled', false)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.