1

我正在尝试 tagsinput 插件在由 jquery 对话框插件调用加载的 div 内的 textarea 中工作。

使用的插件是/xoxco/jQuery-Tags-Input。

我进行了初步检查 textarea 元素是否准备就绪。在被调用之前是while。

标签输入插件不会将文本区域显示为标签。但是,当我在浏览器中从 firebug 尝试相同的操作时:

 $('#textarea').importTags('guava','cherry'); // this works

下面的代码:

jsp文件:

<div id="mydialog">
<textarea name="tags" id="textareaId">
</div>

javascript文件:

$(document).ready(function(){

$("#mydialog").dialog({
    modal: true,
    draggable: false,
    resizable: false,
    position: ['center', 'top'],
    show: 'blind',
    hide: 'blind',
    width: 400,
    dialogClass: 'ui-dialog-osx',
    buttons: {
        "YES": function() {
            $(this).dialog("close");
        }
    }
});

$('#textarea').tagsInput({
   'autocomplete_url': '',
   'autocomplete': { 
       source: ['apple','banana'],
       autofill:true
    },
   'height':'100px',
   'width':'300px',
   'interactive':true,
   'defaultText':'add a tag',
});
$('#textarea').importTags('guava','cherry');
});

任何帮助为什么?

4

1 回答 1

0

在调用 tagsinput 之前,文档中的 $('#textarea') 尚未准备好。我延迟了对 tagsinput 的调用,它工作正常。

于 2016-09-22T06:09:56.080 回答