jQuery tags input 使用
2015-11-12 19:50
585 查看
由于项目中想使用tagsinput添加数据,找了很多资源,最终在github上找到开源的项目:
http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
项目中详细介绍了tagsinput的使用,下面只讲解下添加数据的使用。
1、对于只是添加一个text,就很简单。直接在javascript中使用
2、如果是想添加对象,那么就稍微复杂一点:
首先在
然后在在javascript代码中:
http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
项目中详细介绍了tagsinput的使用,下面只讲解下添加数据的使用。
1、对于只是添加一个text,就很简单。直接在javascript中使用
$('input').tagsinput('add', 'some tag');
2、如果是想添加对象,那么就稍微复杂一点:
首先在
<input>标签中不能加 data-role=’tagsinput’属性。
然后在在javascript代码中:
var organization = new Bloodhound( { datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'), queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'Resources/xenon/assets/organization.json'//json文件可以是空的,应该只是为了能够保存 }); organization.initialize();//初始化 $('#field-organizationresult').tagsinput({ itemValue: 'id', itemText: 'text', typeaheadjs: { name: 'organization', displayKey: 'text',//tagsinput显示的列 source: organization.ttAdapter() } }); $('#field-organizationresult').tagsinput('add', {'id':json.id,'text':json.name});//在tagsinput中添加一个对象
相关文章推荐
- 浅析JQuery中的html(),text(),val()区别
- jquery 字符串转dom对象及对该对象使用选择器查询
- jQuery tags input 使用
- jquery——九宫格大转盘抽奖
- jquery插件开发
- JQuery的父、子、兄弟节点查找,节点的子节点循环
- jquery,2048小游戏粗制版
- jQuery-1.9.1源码分析系列(五) 回调对象
- jquery的promise实践--连续加载图片
- jquery的promise实践--连续加载图片
- jquery的has、find和filter函数的异同
- jQuery EasyUI Combotree 实现ComboBox的内容过滤
- jquery mobile显示加载提示,并自动消失
- 插件--滚动插件slimScroll
- jquery轮播图
- jquery适用函数
- jQuery学习之prop和attr的区别
- JavaScript 中的window.event代表的是事件的状态,jquery事件对象属性,jquery中如何使用event.target
- jQuery 获取屏幕高度、宽度
- jquery 元素控制(追加元素/追加内容)介绍及应用