禁用 jquery 多选
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6531809/
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
Disable the jquery multiselect
提问by John x
How can i disable the multiselected plugin
如何禁用多选插件
in the above link its toggled i want to enable or disable depending upon a particular condition.
在上面的链接中,我想根据特定条件启用或禁用它。
tnx for the help.
tnx 寻求帮助。
采纳答案by ThoKra
Don't know how much JavaScript you know, but $widget.multiselect('disable');
will disable the selector (stored in the variable $widget
). And by replacing disable
with enable
you can enable it.
不知道你对 JavaScript 了解多少,但是$widget.multiselect('disable');
会禁用选择器(存储在变量中$widget
)。并通过替换disable
为enable
您可以启用它。
So just run the function with the correct disable/enable setting and you can do it based on any condition.
因此,只需使用正确的禁用/启用设置运行该功能,您就可以根据任何条件进行操作。
Terw
特尔
回答by LeftyX
$("#mymultiselect").multiselect("disable");
should do the trick.
应该做的伎俩。
HTML:
HTML:
<select id="test001" multiple="multiple" size="5">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
<option value="option4">Option 4</option>
<option value="option5">Option 5</option>
</select>
Javascript:
Javascript:
$("#test001").multiselect({
minWidth: 300,
height: 150,
header: false,
noneSelectedText: "Select",
selectedList: 3
});
Calling $("#test001").multiselect("disable");
will disabled the multiselect.
调用$("#test001").multiselect("disable");
将禁用多选。
Here's an jsfiddle
这是一个jsfiddle
回答by K6t
if you change find("input:checked").length > 3
you can possible to select 3 value For ur wish you can change the.. value and get... your answer
如果你改变find("input:checked").length > 3
你可以选择 3 个值如果你 希望你可以改变..值并得到......你的答案
if( $(this).multiselect("widget").find("input:checked").length > 2 ){
回答by geostima
I've updated the original fiddle posted earlier adding an enable button as well for quicker reference. http://jsfiddle.net/cSq2L/180/
我已经更新了之前发布的原始小提琴,还添加了一个启用按钮以便更快地参考。 http://jsfiddle.net/cSq2L/180/
$("#test001").multiselect({
minWidth: 300,
height: 150,
header: false,
noneSelectedText: "Select",
selectedList: 3
});
$("#changeStatus").click(function()
{
$("#test001").multiselect("disable");
});
$("#changeStatuss").click(function()
{
$("#test001").multiselect("enable");
});