我有一个输入
<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]);
}
关于jQuery TextExt 插件 : add tag after keypress "space" and click on some button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26183608/