我正在使用以下库自动完成并在我的应用程序中提及用户名。我的问题是如何从onClick锚标签触发init:function而不是在文本区域写入。有什么建议吗?这是我试图写的功能。 这是插件 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
});
答案 0 :(得分:2)
如果查看文档(“方法”部分),init()
方法实际上是在插件实例上公开的。例如:
var mention = $('textarea.mention').mentionsInput({}); // Apply the plugin
mention.init(); // call the init() method
答案 1 :(得分:1)
不确定这是问题的根源,但
$("a").on('click', '.tag_user_btn', function(event) { //WRONG
这是错的。 jQuery documentation for .on()
更正语法$(parentSelector).on('click', 'childSelector', function()
而是使用(用于ajax事件处理)
$(document).on('click', 'a.tag_user_btn', function(event) {
或非ajax事件处理
$('a.tag_user_btn').click(function(event)
这是一个简写
$('a.tag_user_btn').on('click', function(event))