这里可能是您的出发点。 它只是使用jQuery。
您需要添加自动完成,验证等。
按Enter键添加标签。
HTML
<div class="form-group">
<label for="exampleInputTags">Tags</label>
<input class="form-control" id="exampleInputTags" placeholder="Enter tags">
</div>
<div id="tags"></div>
JS
var tag = '';
$("#exampleInputTags").keyup(function (e) {
if (e.keyCode == 13) {
tag = '#' + $("#exampleInputTags").val();
$("#tags").append(tag + '<br/>');
$("#exampleInputTags").val('');
}
});
http://jsfiddle.net/iambnz/b7gju2c1/
编辑:
我已经添加了自动完成一些逻辑。 RegEx模式应该被测试和改变。 到目前为止,不知道如何将其添加到输入上下文中。
JS
var tag = '';
var str = 'JavaScript';
$("#exampleInputTags").keyup(function (e) {
var re = $("#exampleInputTags").val();
console.log(re);
if (re != '')
{
testinput(re, str);
}
else if (re == '')
{
$("#suggestions").text('');
}
});
function testinput(re, str) {
if (str.search(re) != -1) {
$("#suggestions").text(str);
}
}
$("#exampleInputTags").keyup(function (e) {
if (e.keyCode == 13) {
tag = '#' + $("#exampleInputTags").val();
$("#tags").append(tag + '<br/>');
$("#exampleInputTags").val('');
}
});
HTML
<div class="form-group">
<label for="exampleInputTags">Tags</label>
<input class="form-control" id="exampleInputTags" placeholder="Enter tags">
</div>
<div id="tags"></div>
<br/><br/>
<div id="suggestions"></div>
http://jsfiddle.net/iambnz/yye1b4ye/
如果所有不符合您的需求,拿上一看预输入从引导加上。
http://getbootstrap.com/2.3.2/javascript.html#typeahead