我正在使用以下库来自动完成并在我的应用程序中提及用户名。我的问题是,如何从 anchor 标记的 onClick 触发 init: 函数,而不是在文本区域中写入。有什么建议吗?这是我尝试编写的一个函数。 这是插件 http://podio.github.io/jquery-mentions-input/
$("a").on('click', '.tag_user_btn', function(event) {
event.preventDefault();
var txtPost = $(this).parents('.post-comment').find('textarea');
txtPost.val(txtPost.val()+" @a").focus().init();//call initilize function of library
});
最佳答案
如果您查看文档(“方法”部分),init()
方法实际上是在插件实例上公开的。示例:
var mention = $('textarea.mention').mentionsInput({}); // Apply the plugin
mention.init(); // call the init() method
关于javascript - 从外部点击事件调用 jQuery 插件内的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28279956/