【问题标题】:Add tags to tag bar using xoxco tag plugin使用 xoxco 标签插件将标签添加到标签栏
【发布时间】:2014-06-16 13:30:27
【问题描述】:

我试图从单词列表中添加标签,只需单击单词即可添加。我尝试向 HTML 中的输入添加一个新值,但这并没有在其中添加新标签。

    $("li").click(function() {
        var word = $(this).text();

        var value = $('.tagBar').attr('value');
        var newValue = value+","+word;
        $('.tagBar').attr('value', newValue);
    });

然后我尝试使用 addTag(value,options) 代替,但我不断收到错误。

如何在不输入框并单击的情况下添加新标签?

【问题讨论】:

    标签: javascript jquery tags


    【解决方案1】:

    我有一个下拉列表和一个按钮,让用户可以使用 Xoxco 标签输入控件在标签列表中添加多个项目。我就是这样做的:

    $("#btnAgregarMaterial").click(function (e) {
            e.preventDefault(); // avoids submitting the form
    
            var control = $("#cbbMateriales"); // gets drop down list
            var value = control.data("value"); // gets item value (ID)
            if (value > 0) { // if it is an item with ID greater than zero
                var text = control.text(); // get item text
                var tagsControl = $("#tags"); // gets tags input control
                tagsControl.addTag(text); // adds tag using addTag function
            }
        });
    

    为了添加标签,您需要使用函数addTag。直接设置值是行不通的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      相关资源
      最近更新 更多