添加删除到文本区域内的内容类似于电子邮件客户端

Adding Delete to content inside textarea similar to Email Client

本文关键字:类似于 电子邮件 客户端 添加 文本 区域 删除      更新时间:2023-09-26

我使用jquery自动完成添加值到我的文本框。我想添加的功能完全像任何电子邮件服务。你添加一个电子邮件,它变成一个框,你可以从文本框中删除它。或者你可以在这里给你的问题添加标签。如果需要textarea不重要,只要试着得到像电子邮件一样的东西。

我的自动完成功能只是添加值到我的id为'#name'的文本框

    $("#name").autocomplete({
    minLength: 3,
    source: function (request, response) {
        $.getJSON("/getData", {
            term: extractLast(request.term)
        }, response);
    },
    select: function (event, ui) {
        var terms = split(this.value);
        terms.pop();
        if(ui.item.label == 'Create New') {
            $('.add-user').show();
        }
            terms.push(ui.item.label);
            terms.push("");
            this.value = terms.join(", ");
            //Get the ids associated with the name selected adding to a hidden field called #userId
            var id = split($('#userId').val());
            id.pop();
            id.push(ui.item.id);
            id.push("");
            $('#userId').val(id.join());
            return false;
    },
    focus: function () {
        return false;
    }
});

不需要重新发明轮子

查找jquery的select2库:

https://select2.github.io/examples.html标签

干杯!:)