簡體   English   中英

如何禁用選定的下拉列表?

[英]How to disable a chosen drop down list?

我拼命地試圖通過 jQuery (1.11.3) 禁用選定的下拉列表。 以下代碼行是我讓它工作的所有嘗試:

$("#jform_catid_chzn").prop('disabled', true).trigger('listz:updated');
$("#jform_catid_chzn").prop('disabled', 'disabled').trigger('listz:updated');
$("#jform_catid_chzn").attr('disabled', true).trigger('listz:updated');
$("#jform_catid_chzn").attr('disabled', 'disabled').trigger('listz:updated');
$("#jform_catid_chzn").prop('disabled', true).trigger('chosen:updated');
$("#jform_catid_chzn").prop('disabled', 'disabled').trigger('chosen:updated');
$("#jform_catid_chzn").attr('disabled', true).trigger('chosen:updated');
$("#jform_catid_chzn").attr('disabled', 'disabled').trigger('chosen:updated');

不幸的是,到目前為止,他們都沒有成功。 當然,我檢查了觸發的 id,它是正確的。

有人可以幫我解決這個問題嗎?

使用JavaScript

 <script> function disable() { document.getElementById("mySelect").disabled=true; } function enable() { document.getElementById("mySelect").disabled=false; } </script> </head> <body> <select id="mySelect"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> </select> <br><br> <input type="button" onclick="disable()" value="Disable list"> <input type="button" onclick="enable()" value="Enable list"> 

使用jquery

 $(document).ready(function() { $("#chkdwn2").click(function() { if ($(this).is(":checked")) { $("#dropdown").prop("disabled", true); } else { $("#dropdown").prop("disabled", false); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <select id="dropdown" style="width:200px;"> <option value="feedback" name="aft_qst">After Quest</option> <option value="feedback" name="aft_exm">After Exam</option> </select> <input type="checkbox" id="chkdwn2" value="feedback" /> 

剛剛偶然發現這個問題,因為我遇到了同樣的問題,但仍然沒有解決..

$("#jform_catid_chzn").attr('disabled', true).trigger('listz:updated');

它應該是:

$("#jform_catid").attr('disabled', true).trigger('liszt:updated');
  1. 當您使用插件命令時,您的目標是原始下拉列表(沒有“_chzn”)
  2. “listz”現在應該是“listz”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM