//选项的个数 jquery.fn.size = function() { return jquery(this).get(0).options.length; } //获得选中项的索引 jquery.fn.getselectedindex = function() { return jquery(this).get(0).selectedindex; } //获得当前选中项的文本 jquery.fn.getselectedtext = function() { if(this.size() == 0) { return ""; //下拉框中无选项 } else { var index = this.getselectedindex(); return jquery(this).get(0).options[index].text; } } //获得当前选中项的值 jquery.fn.getselectedvalue = function() { if(this.size() == 0) { return ""; //下拉框中无选中值 } else { return jquery(this).val(); } } //获得当前选中的项的option 对象 jquery.fn.getselectoption=function() { if(this.size() == 0) { return ""; //下拉框中无选项 } else { var index = this.getselectedindex(); return jquery(this).get(0).options[index]; } } //获得当前的所有option 对象 jquery.fn.getselectoptions=function() { if(this.size() == 0) { return ""; //下拉框中无选项 } else { return jquery(this).get(0).options; } } //设置select中值为value的项为选中 jquery.fn.setselectedvalue = function(value) { jquery(this).get(0).value = value; } //设置select中文本为text的第一项被选中 jquery.fn.setselectedtext = function(text) { var isexist = false; var count = this.size(); for(var i=0;i= count || index < 0) { alert("选中项索引超出范围"); } else { jquery(this).get(0).selectedindex = index; } } //判断select项中是否存在值为value的项 jquery.fn.isexistitem = function(value) { var isexist = false; var count = this.size(); for(var i=0;i= count || index < 0) { //return false; alert("待删除项索引超出范围"); } else { jquery(this).get(0).remove(index); } } //删除select中选定的项 jquery.fn.removeselected = function() { var index = this.getselectedindex(); this.removeindex(index); } //清除select中的所有项 jquery.fn.clearall = function() { jquery(this).get(0).options.length = 0; } $(document).ready(function(){ $("a").focus(function() { $(this).blur(); }); //可以防止a标签出现虚线阴影 });