2017-01-05 28 views
0

編集でドロップダウンを無効にするにはどうすればよいですか? MVCビューでドロップダウンし、jqueryでユーザーを作成および編集します。私はすでに、これらを試してみましたが、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で有効にします。

+1

をあなたのIDは 'organization'、ない' dropdown'や 'dropDownId'です。 (無効)、true); –

+0

$(#組織).prop( '無効'、真) –

+0

https://learn.jquery.com/using-jquery-core/faq/how-do-i-disable-enable-a-form-element/ – epascarello

答えて

5

。あなたが呼び出す必要がありそれを再度有効にするには:

$("#dropdown").removeAttr("disabled"); 

<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').removeAttr('disabled')">Enable</button> 
 
<button onclick="$('#organization').prop('disabled','disabled')">Disable</button>

+0

削除が機能していません。作成ユーザーでも無効になっています。 – Alma

+0

jQueryセレクタを確認してください。ちょうどフィドルが追加されました。 – TimeO84

+0

ここでは動作していますが、おそらくModalで有効にしたり無効にしたりするために、別のものがあり、何かがありません。 – Alma

1

ドロップダウンを再度有効にするには、属性をすべて削除する必要があります。あなたがコントロールを無効にする

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

を設定する必要が

$('#dropdown').removeAttr('disabled')

関連する問題