2012-09-12 105 views

回答

1

基于在github上自己的代码,你可以试试这个作为一种解决方法:

$('#input').on('paste',function() { 
    $(this).trigger('keypress'); 
}); 
1

的其他简单的解决方案是

$('#tags').tagsInput({ 
    'onAddTag': function(tag) { 
     //Remove all newlines 
     tag = tag.replace(/\n/g, ''); 
     //Remove all spaces 
     tag = tag.replace(/\s/g, ''); 
     //check if a comma is find inside var tag 
     if (tag.indexOf(',') > 0) { 
      $('#tags').importTags(tag); 
     }; 
    } 
}); 

瞧!

0

这种支持粘贴逗号分隔字符串

onAddTag: function(tag) { 
    var tags = tag.split(","); 
    if(tags.length > 1) { 
     $(this).removeTag(tag); 
     return false; 
    } 
    } 

看起来有点怪异,但标记库已经把逗号作为分隔符,所以删除只是刷新。

0

我发现坑挖掘机的初始问题与双标签的原因。 $(e.target).val()已经添加了标签。添加+ ',' + e.tags只会使标签加倍。在我的解决方案中,我评论了旧版本,并在上面添加了新行。

原始代码:https://github.com/xoxco/jQuery-Tags-Input/issues/22

var tidyTags = function(e) { 
    var tags = ($(e.target).val()).split(','); 
    //var tags = ($(e.target).val() + ',' + e.tags).split(','); 
    var target = $(e.target); 
    target.importTags(''); 
    for (var i = 0, z = tags.length; i<z; i++) { 
     var tag = $.trim(tags[i]); 
     if (!target.tagExist(tag)) { 
      target.addTag(tag); 
     } 
    } 
    $('#' + target[0].id + '_tag').trigger('focus'); 
};