【问题标题】:Keep first five characters and truncate the other characters in autocomplete?保留前五个字符并在自动完成中截断其他字符?
【发布时间】:2016-07-21 18:51:58
【问题描述】:

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

请在下面找到我的 UI 屏幕:

其实我已经定制了fcbk complete插件,用shift+方向键做多选功能,一次选择多个项目。

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

我的代码如下:

 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...

有什么帮助吗?

【问题讨论】:

    标签: javascript jquery autocomplete fcbkcomplete


    【解决方案1】:

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

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

    试试这个选项...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多