1

中的标签Bootstrap Tags Input溢出容器。

所以我想为标签设置最大宽度,或者有什么方法可以阻止标签溢出Bootstrap Tags Input

如需参考,请访问此网站

4

1 回答 1

1

只需添加一个 Bootstrap-Tagsinput 事件:

$('#Id').on('itemAdded', function(obj) {

    var tagsinputWidth = $('#Id').parent().find('.bootstrap-tagsinput').width();// Width of Bootstrap Tags Input.
    var tagWidth = $('#Id').parent().find('.bootstrap-tagsinput span.tag').last().width();// To get the Width of individual Tag.
    if(tagWidth > tagsinputWidth) {
        //If Width of the Tag is more than the width of Container then we crop text of the Tag
        var tagsText = obj.item.value;// To Get Tags Value
        var res = tagsText.substr(0, 5); // Here I'm displaying only first 5 Characters.(You can give any number)  
        $('#Id').parent().find('.bootstrap-tagsinput span.tag').last().html(res+"..." +'<span data-role="remove"></span>');
    }
});

但问题是,用户看不到他/她添加的标签的全部文本。所以我们可以为标签放置“标题”

我们需要在 bootstrap-tagsinput.js 的第 127 行进行自定义。

var $tag = $('<span class="tag ' + htmlEncode(tagClass) + '" title="'+htmlEncode(itemText)+'">' + htmlEncode(itemText) + '<span data-role="remove"></span></span>');

因此,现在用户可以在将鼠标悬停在该特定标签上时看到文本。

于 2015-05-22T12:25:33.530 回答