jQuery Chosen通用初始化
一直在用Chosen这个js插件,其目的就是美化下拉框。github地址:https://harvesthq.github.io/chosen/
no_results_text:"xxxxx"无搜索结果时显示的文本
allow_single_deselect:true 是否允许取消选择
disable_search: true 是否有搜索框出现
max_selected_options:当select为多选时,最多选择个数
官方说明文档地址
配置选项的官方说明文档地址
/* 功能: Chosen通用初始化
* 创建人:Brian 创建时间:2016-12-13
*/
(function ($j) {
var chosenTool = function (el, options) {
this.opts = options;
this.chosenInit();
this.chose_get_init();
this.chose_mult_set_init(this.opts.hidClassName);
this.clickEvent();
return this;
}
chosenTool.opts = {
selectId: '',//selectId
hidClassName: '',//隐藏域Class
placeholdertxt: '',//select中placeholder文字
noresulttxt: '',//输入的名称未查到时显示的文字
dataJson: ''//数据源
};
$j.fn.myChosenTool = function (opt) {
var value,
args = Array.prototype.slice.call(arguments, 1);
var $jthis = $j(this),
data = $jthis.data('chosenTool'),
options = $j.extend({}, chosenTool.opts, $jthis.data(),
typeof option === 'object' && option);
if (typeof option === 'string') {
//判断用户调用的方法是否存在
//if ($j.inArray(option, allowedMethods) < 0) {
// throw new Error("Unknown method: " + option);
/