/*! * select v0.0.1 * by Liuyuchao * Copyright 2015.2 * Date: Tue Feb 25 2015 */ ;(function($,window,document){ var pluginName = 'selectlist', defaults = { //默认属性配置 enable: true, //选择列表是否可用 zIndex: null, //选择列表z-index值,如需兼容IE6/7,必须加此属性 width: null, //选择列表宽度 height: null, //选择列表高度 border: null, //选择列表边框 borderRadius: null, //选择列表圆角 showMaxHeight: null, //选择列表显示最大高度 optionHeight: 34, //选择列表单项高度 triangleSize: 6, //右侧小三角大小 triangleColor: '#333', //右侧小三角颜色 topPosition: false, //选择列表项在列表框上部显示,默认在下边显示 speed: 100, //选择列表框显示动画速度(毫秒) onChange: function(){} //自定义模拟选择列表项change事件 }; function SelectList(element,options){ this.element = element; this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.init(); } SelectList.prototype={ init: function(){ var that = this, element = this.element; that.replaceProtoypeSelect(element); that.setSelectEvent(element); that.setSelectStyle(element); }, //获取原生选择列表id值 getSelectID: function(element){ var $this = $(element), selectID = $this.attr('id'); if(typeof(selectID) !== 'undefined'){ return selectID; }else{ selectID=''; return selectID; } }, //获取原生选择列表name值 getSelectName: function(element){ var that = this, $this = $(element), selectName = $this.attr('name'); if(typeof(selectName) !== 'undefined'){ return selectName; }else{ return that.getSelectID($this); } }, //获取原生选择列表class名 getSelectClassName: function(element){ var $this = $(element), tempClassNameArray = [], classNameArray = [], className = $this.attr('class'); if(typeof(className) !== 'undefined'){ classNameArray = className.split(' '); classNameArray.sort(); tempClassNameArray =[classNameArray[0]]; for(var i = 1; i < classNameArray.length; i++){ if( classNameArray[i] !== tempClassNameArray[tempClassNameArray.length-1]){ tempClassNameArray.push(classNameArray[i]); } } return tempClassNameArray.join(' '); }else{ className=''; return className; } }, //获取原生选择列表选中索引值 getSelectedIndex: function(element){ var $this = $(element), selectedIndex = $this.get(0).selectedIndex || 0; return selectedIndex; }, //获取原生选择列表option的数量 getOptionCount: function(element){ var $this = $(element); return $this.children().length; }, //获取原生选择列表option的内容 getOptionText: function(element){ var that = this, $this = $(element), $option = $this.children(), optionText = [], selectLength = that.getOptionCount($this); for(var i=0;i