1,selec2动态赋值
代码如下 | 复制代码 |
vartemp=JSON.stringify({ id:"1|所有停车场", name:"所有停车场"}); $("#e_pid").attr("value", tempP); $("#e_pid").select2({ placeholder:"查找停车场名称(多选)", language:"zh-CN", minimumInputLength: 1, allowClear:true, multiple:true, ajax: { // instead of writing the function to execute the request we use Select2's convenient helper url:"/manage/park/index/json/index", dataType: 'json', data: function (term, page) { return { parkName: term,// search term powerpid: "1" }; }, results: function (data, page) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to alter remote JSON data for (var i = 0; i < data.length; i++) { data[i].id = data[i].id+"|"+data[i].name; }; data.push({ id: "577cb125f8d2c404572413d1|无", name: "无" }); return { results: data }; } }, initSelection: function (element, callback) { //赋初始值 // the input tag has a value attribute preloaded that points to a preselected movie's id // this function resolves that id attribute to an object that select2 can render // using its formatResult renderer - that way the movie name is shown preselected vardata = []; varvalue ="" varstr = $(element).val().split('^'); for(vari = 0; i < str.length; i++) { vartemp = JSON.parse(str[i]); value += temp.id +","; data.push(temp); } ; value = value.substring(0, value.length - 1); $(element).val(value); callback(data); }, formatSelection:function(item) { returnitem.name;//注意此处的name,要和ajax返回数组的键值一样 },// 选择结果中的显示 formatResult:function(item) { returnitem.name;//注意此处的name },// 搜索列表中的显示 dropdownCssClass:"bigdrop",// apply css that makes the dropdown taller escapeMarkup:function(m) { returnm; } }); |
2,动态改变值
代码如下 | 复制代码 |
$("#e_pid").attr("value", temp); $("#e_pid").trigger('change');//动态改变值以后必须触发改变时间。否则将不会生效 |
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级