使用jquery tagit插件,我怎样才能禁用特定的盒子?

时间:2014-10-06 13:04:43

标签: javascript jquery css tag-it

我已经看到以下代码(Using jquery tagit plugin, Is there anyway to disable all entry?)允许禁止进入tagit字段,但这会影响所有tagit框。我希望能够禁用启用复选框时受影响的特定标签条目。如果我只想禁用特定的标签框,是否可以使用此方法?

这是我从示例中添加的css代码:

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

由于我无法将上述内容用于特定的标签框而非适用于所有标签框,因此我采用了这种方法:

$('#global').on('click', function(){
    if ( $(this).is(':checked') ) {
        $('#region').tagit("removeAll");
        $('#region').tagit({
             showAutocompleteOnFocus: false, placeholderText: "Global...",
             requireAutocomplete: false,
             tagSource: function()
             {
                    $.ajax({
                        data: {term: " "},
                        success: function(data){
                            return data;
                        }
                    });        
             },
             beforeTagAdded: function(event, ui) {
                     return false;
             }, 
         });
       }
    else {
        $('#region').tagit({
            showAutocompleteOnFocus: true, placeholderText: "Select a region...",
            requireAutocomplete: true,
            allowSpaces:true,
            tagSource: function(request, response) 
            {
                $.ajax({
                    data: { term:request.term },
                    type: "GET",
                    url: "${pageContext.request.contextPath}/region_list",
                    dataType: "json",
                     success: function( data ) {
                        array = data;
                        response($.map(data, function( item ) {
                            return {
                                label: item,
                                value: item
                            };
                            }));
                        }
                });
                },
            beforeTagAdded: function(event, ui) {
                if(array.indexOf(ui.tagLabel) == -1)
                {
                    return false;
                }
                if(ui.tagLabel == "not found")
                {
                    return false;
                }
            },
        }); 
    }
});

上面的代码删除了标记的选项,并且不允许您添加条目,但我想要整体禁用该框,以便下拉列表中不显示任何内容。

0 个答案:

没有答案