Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用TagsInput从输入字段获取文本值_Javascript_Html_Ruby On Rails - Fatal编程技术网

Javascript 使用TagsInput从输入字段获取文本值

Javascript 使用TagsInput从输入字段获取文本值,javascript,html,ruby-on-rails,Javascript,Html,Ruby On Rails,我试图在使用TagsInput库时从文本字段获取输入值 这是我的html字段 <input class="tagsinput form-control" type="text" data-role="tagsinput" id="tagsinput"/> 但我只能在如下创建“标记”时获取文本框中的值 这就是我获取值并将其分配给数组的方式 但当我只键入单词而不按enter键创建标记时,如下所示: 该值不会添加到数组中,因为它不是“标记” 因此,我试图实现的是在点击add按钮后创

我试图在使用TagsInput库时从文本字段获取输入值

这是我的html字段

<input class="tagsinput form-control" type="text" data-role="tagsinput" id="tagsinput"/>
但我只能在如下创建“标记”时获取文本框中的值

这就是我获取值并将其分配给数组的方式

但当我只键入单词而不按enter键创建标记时,如下所示:

该值不会添加到数组中,因为它不是“标记”

因此,我试图实现的是在点击add按钮后创建一个标记。无需按enter键即可创建实际标记

$('.tagsinput').tagsinput({
  trimValue: true,
  tagClass: 'label label-primary',
  typeaheadjs: {
    name: 'organizationtags',
    display: 'name',
    valueKey: 'name',
    source: bloodhound.ttAdapter()
  }
});