2

我有一个带有多个标记的自动完成文本框。我想检查前五个输入的字符以匹配和截断其他字符。

请在下面找到我的 UI 屏幕: 在此处输入图像描述

实际上,我已经使用 shift + 箭头键自定义了 fcbk 完整插件来执行多选功能以一次选择多个项目。

我想检查前五个字符以匹配并仅截断其他字符...

我的代码如下:

 var addItem = function(item, preadded){
    console.log(item);
    if(item.length > 1)
    {

        for (var i=0;i<item.length;i++)
        {
            var title = $(item[i]).text();
            console.log('Title = ' + title);
            var value = ($(item[i]).attr('rel') && $(item[i]).attr('rel') != -1 ? $(item[i]).attr('rel') : title);
            var li = document.createElement('li');
            var txt = document.createTextNode(title);
            var aclose = document.createElement('a');
            var input = addHiddenInput(value);
            $(li).attr({
                'class': 'bit-box'
            });
            $(li).prepend(txt);
            $(aclose).attr({
                'class': 'closebutton',
                'href': '#'
            });
            li.appendChild(aclose);
            li.appendChild(input);
            holder.appendChild(li);
            $(aclose).click(function(){
                $(this).parent('li').fadeOut('fast', function(){
                    $(this).remove();
                });
                return false;
            });
             item[i].remove();
        }
    }
    else
    {

    console.log(item);
    var title = item.text();
    console.log('title = ' + title);
    var value = (item.attr('rel') && item.attr('rel') != -1 ? item.attr('rel') : title);
    var li = document.createElement('li');
    var txt = document.createTextNode(title);
    var aclose = document.createElement('a');
    var input = addHiddenInput(value);
    $(li).attr({
        'class': 'bit-box'
    });
    $(li).prepend(txt);
    $(aclose).attr({
        'class': 'closebutton',
        'href': '#'
    });
    li.appendChild(aclose);
    li.appendChild(input);
    holder.appendChild(li);
    $(aclose).click(function(){
        $(this).parent('li').fadeOut('fast', function(){
            $(this).remove();
        });
        return false;
    });
     }
    if (!preadded) {
        holder.removeChild(document.getElementById(elem[0].id));
        addInput(elem);
    }
     if(!controlKeyPressed){
    feed.hide();
}
item.remove();
}

这是我的 addItem 函数,其中 mutiselect 值被添加到带有标记的自动完成文本框中。

我的预期输出:

Manuel...

对此有什么帮助吗?

4

1 回答 1

1

嘿,你可以像下面的代码一样实现你的东西:

    txt.substr(0, txt.length - 1);
    $(li).html(txt + "...");

试试这个选项...

于 2016-07-21T10:51:58.060 回答