如何禁用选定的下拉列表

How to disable a chosen drop down list?

本文关键字:下拉列表 何禁用      更新时间:2023-09-26

我拼命地试图通过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,它是正确的。

有人可以帮我吗?

只是偶然发现了这个问题,因为我遇到了同样的问题,但仍然没有解决。.

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

它应该是:

$("#jform_catid").attr('disabled', true).trigger('liszt:updated');
  1. 当您使用插件命令时,您的目标是原始命令下拉列表(不带"_chzn")
  2. "
  3. listz"现在应该是"liszt"

使用 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" />