问题描述
我有一个页面,我正在使用 jquery tagit插件,该插件效果很好,但我试图在我单击按钮时禁用它,并且它具有与我禁用选择下拉菜单时类似的行为:
I have a page and i am using jquery tagit plugin which works great but i am trying to disable it when i click on a button, and have it have similar behavior to when i disable a select Dropdown like this:
$("#selectDropdown").val(0);
$('#selectDropdown').prop('disabled', 'disabled');
总有办法以编程方式禁用和启用jquery tagit插件.我看到文档页面上有一个只读选项 尝试做这样的事情:
Is there anyway to disable and enable the jquery tagit Plugin programatically. I see there is a readonly option on the docs page so I tried doing something like this:
$("#locationTags").tagit({ "readOnly": false });
但这似乎无济于事.
有什么建议吗?
推荐答案
以下内容演示了如何禁用/启用tagit
字段.
The following demonstrates how you could disable/enable a tagit
field.
已使用David的优化代码进行了更新.
$('#disable').click(function(){
$('.ui-autocomplete-input').prop('disabled', true).val('');
$('.tagit-choice').remove();
$('.ui-widget-content').css('opacity','.2');
});
$('#enable').click(function(){
$('.ui-widget-content').css('opacity','1');
$('.ui-autocomplete-input').prop('disabled', false);
});
示例
http://jsfiddle.net/davidThomas/j8Eg4/1/
因为您希望该字段看起来像一个禁用的下拉菜单,所以我选择了此解决方案. tagit
支持的另一种解决方案是,如果要停止添加标签,可以使用beforeTagAdded (function, Callback)
功能.并返回false以阻止创建新标签...
Because you want the field to look like a disabled dropdown I opted for this solution. Another solution that tagit
supports is if you want to stop tags from being added you can utilize the beforeTagAdded (function, Callback)
function. And return false in order to stop new tags from being created...
这是一个例子.
这篇关于使用jquery tagit插件,是否有禁用所有条目的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!