$('input').tagsinput({ itemValue: 'value', itemText: 'text', source: function(query) { return [{ "value": 1 , "text": "阿姆斯特丹" }, { "value": 2 , "text": "马德里" }]; } });
- Ferus7你可以使用这个 JQuery 插件
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
<link href="css/jquery.tagit.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>
<ul id="myTags">
<!-- Existing list items will be pre-added to the tags -->
<li>Tag1</li>
<li>Tag2</li>
</ul>
<script type="text/javascript">
$(document).ready(function() {
$("#myTags").tagit();
});
$("#myTags").tagit({
availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"],
readOnly: true,
});
</script>
这可能会特别有助于关于Stack Overflow的标签选择 -> Stack Tags以及使用像bootstrap这样的框架可以让您更轻松地完成,就像已经提到的那样。