jQuery TextExt 插件 : add tag after keypress "space" and click on some button

标签 jquery jquery-plugins

我有一个输入

<input type="text" style="width:200px" id="myInputTags" placeholder="add tag" />
<input type="button" id="btnId" />

在脚本中

jQuery("#myInputTags").textext({ plugins: 'tags' });

现在,当我在此输入中按 Enter 时,将创建标签,但我想在单击按钮后并按“空格”后添加此标签 有什么建议吗?

最佳答案

嗨。

jQuery("#myInputTags")
    .textext({
        plugins: 'tags, prompt', 
        prompt: 'add tag'
    })
   .keypress(function(event){
     //'Space' key is pressed in keyboard
     if(event.which==32){
       addTag();
     }
   });

jQuery("#btnId").click(function(){
    addTag();
})

function addTag(){
    //Take the value from text input
    var tag = $('#myInputTags').val();

    //Clear the text input and add tag
    $('#myInputTags').val('').textext()[0]
    .tags().addTags([tag]);
}

See a Live Demo of this

文档: TexExt - Adding Tags Directly

关于jQuery TextExt 插件 : add tag after keypress "space" and click on some button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26183608/

相关文章:

javascript - 隐藏字符导致JQuery函数失败

jquery - jquery 准备好后在 Canvas 上绘图

javascript - jQuery 通过 Div 中的多个图像在 MouseOver 上淡入淡出

javascript - 如何更改 Javascript 的默认日期格式?

javascript - .uploadifySettings 未按预期工作

javascript - Angularjs 选项卡按钮

jquery - 在悬停时显示 gif 以获取可调整大小的图像映射

javascript - Jquery + 最新的哈希更改监听器?

jquery-plugins - 自动完成 jquery

javascript - 实现 jquery UI 自动完成以在您键入 "@"时显示建议