使用jquery tagit插件,是否有禁用所有条目的功能? [英] Using jquery tagit plugin, Is there anyway to disable all entry?

查看:110
本文介绍了使用jquery tagit插件,是否有禁用所有条目的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我正在使用 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...

这是一个例子.

http://jsfiddle.net/j8Eg4/2/

这篇关于使用jquery tagit插件,是否有禁用所有条目的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆