简体   繁体   中英

Disable and Enable drop down using jquery

How I can make my drop down disable in Edit but enable in Create User. I have the drop down in MVC view and Create and Edit user in jquery. I already tried these but not making it disabled using any of these in jquery:

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

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

 $('#dropdown').prop('disabled', true);

and in my MVC with when I have like this:

  <select id="organization" class="create-user-select-half" disabled>

it making it disabled but I can not again Enable it in jquery.

You have to set

$("#dropdown").prop('disabled', true);

for disabling a control. To enable it again you have to call:

$("#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; }

a disabled item is un-clickable. you can use a div outside of your select tag.

<div class="editable">
      <select id="organization" class="create-user-select-half" disabled>
</div>

$(".editable").on("click", function () {
    $('#organization').prop('disabled', false)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM