javascript 选中复选框时禁用选择下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27256960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disabling selectize dropdown when a checkbox is checked
提问by Gagan
I have implemented selectizeon my html form. However a dropdown only becomes active when the "enable" checkbox is clicked. I know there is a disable property on the selectize object but I dont know how to use it when the checkbox is clicked.
我已经在我的 html 表单上实现了选择。但是,只有单击“启用”复选框时,下拉列表才会变为活动状态。我知道 selectize 对象上有一个禁用属性,但我不知道在单击复选框时如何使用它。
I have tried adding the disabled class to the selectize div element but that does not work either. Any help will be well appreciated.
我尝试将禁用的类添加到 selectize div 元素,但这也不起作用。任何帮助将不胜感激。
Thanks
谢谢
回答by JNYRanger
I wanted to add an additional answer here because although @tclark333's answer is correct, it's a bit misleading since the first line is the actual initialization of the selectize object, and not actually what's needed for the answer.
我想在这里添加一个额外的答案,因为虽然@tclark333 的答案是正确的,但它有点误导,因为第一行是 selectize 对象的实际初始化,而不是实际需要的答案。
The selectize API is exposed when you access the selectize property on the underlying element from a jQuery object and not as an extension to jQuery itself.
selectize API 在您从 jQuery 对象访问底层元素上的 selectize 属性时公开,而不是作为 jQuery 本身的扩展。
Assuming the element that has been selectized's ID is "myDropDown":
假设已被选中的元素的 ID 是“myDropDown”:
//disable
$('#myDropDown')[0].selectize.disable();
//re-enable
$('#myDropDown')[0].selectize.enable();
回答by tclark333
It's a little weird how you have to set it up. Here's what works for me.
你必须如何设置它有点奇怪。这对我有用。
var select = $("#YourDropDownId").selectize();
var selectize = select[0].selectize;
selectize.disable();
回答by Master Sh
function generateCircle(id , jPath){
var formId =$("#"+id).closest(".data_details_accord").find("form");
var select = formId.find("select");
/*disable select initially*/
select.each(function(){
var thisSelect = $(this).selectize();
thisSelectDisable = thisSelect[0].selectize;
thisSelectDisable.disable();
});
/***********/
$.ajax({
url: jPath,
data:formVlaz,
success: function(result){
},error: function (xhr , status, eror) {
},complete: function (xhr) {
/*enable select when ajax complete*/
select.each(function(){
var thisSelect = $(this).selectize();
thisSelectDisable = thisSelect[0].selectize;
thisSelectDisable.enable();
});
/********/
}
});
};