简体   繁体   English

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

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

I'm desperatly trying to disable a chosen drop down list through jQuery (1.11.3).我拼命地试图通过 jQuery (1.11.3) 禁用选定的下拉列表。 The following code lines are all my attempts to get it work:以下代码行是我让它工作的所有尝试:

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

Unfortunately none of them has succeeded so far.不幸的是,到目前为止,他们都没有成功。 Of course I've checked the triggered id and it is correct.当然,我检查了触发的 id,它是正确的。

Can someone please help me on this one?有人可以帮我解决这个问题吗?

Using JavaScript 使用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"> 

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

Just stumbled accross this question as I had the same problem and it is still not solved..刚刚偶然发现这个问题,因为我遇到了同样的问题,但仍然没有解决..

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

it should be:它应该是:

$("#jform_catid").attr('disabled', true).trigger('liszt:updated');
  1. when you are using plugin commands you are targeting your original dropdown (without "_chzn")当您使用插件命令时,您的目标是原始下拉列表(没有“_chzn”)
  2. "listz" should now be "liszt" “listz”现在应该是“listz”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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