javascript - 从外部点击事件调用 jQuery 插件内的函数

标签 javascript jquery mention

我正在使用以下库来自动完成并在我的应用程序中提及用户名。我的问题是,如何从 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/

相关文章:

javascript - Div 复选框按属性分组

javascript - ui.router 不显示页面 [嵌套 View ]

javascript - 使用Javascript测量当前窗口

javascript - 有没有办法将 slider 重置为图像 1?

flutter test enterText on widget 扩展 EditableText "Bad state: No element": building editable text for mention

python - Tweepy Mentions_timeline 返回一个空列表

javascript - 如何使用Chrome扩展存储API进行CRUD操作?

jquery - 网站中的全屏背景图像看起来模糊

javascript - 将文本框连同文本添加到 HTML 中的表格 (tbody)