bootstrap可编辑下拉框jquery.editable-select
搜了半天发现在某处下载jquery.editable-select需要积分,于是整理出来方便 其他人。
先上下载链接: http://pan.baidu.com/s/1kUXvwlL password : 5iqn
然后直接请看代码:
引用:
HTML部分:
用量
JS部分:
ajaxDirect(contextPath + "/admin/getDataDictAll/024", {}, function(data) { var htm = ""; for (var int = 0; int < data.length; int++) { htm += ""; } $('#numUnit').html(htm); $('#numUnit').editableSelect({ effects: 'slide', //可选参数default、fade filter: false // 不过滤,否则选中后其它选项消失 }); // $("#numUnit").attr("readonly","true"); // 设置不可编辑 setTimeout(function() { $('#numUnit').val(data[0].name); // 设置默认值,不延时则不生效。 }, 300); });
ajaxDirect 是变了个花样的ajax,可无视
/** * 返回JSON形式的数据 * @param url 地址 * @param data 参数 * @param func 返回函数 * @param async 是否异步 */ function ajaxDirect(url, data, func, async) { if (!async) { async = false; } $.ajax({ url: url, type: "post", dataType: "json", async: async, data: data, success: func }); }
效果如图:
其它选项设置:
- filter:过滤,即当输入内容时下拉选项会匹配输入的字符,支持中文,true/false,默认true。
- effects:动画效果,当触发弹出下拉选择框时的下拉框展示过渡效果,有default,slide,fade三个值,默认是default。
- duration:下拉选项框展示的过渡动画速度,有fast,slow,以及数字(毫秒),默认是fast。
-
事件
- onCreate:当输入时触发。
- onShow:当下拉时触发。
- onHide:当下拉框隐藏时触发。
- onSelect:当下拉框中的选项被选中时触发。