jquery操作select
|
admin
2012年2月3日 0:56
本文热度 4190
|
2 |
jQuery.fn.size=function(){ |
3 |
returnjQuery(this).get(0).options.length; |
7 |
jQuery.fn.getSelectedIndex=function(){ |
8 |
returnjQuery(this).get(0).selectedIndex; |
12 |
jQuery.fn.getSelectedText=function(){ |
13 |
if(this.size()==0)return"下拉框中无选项"; |
15 |
var index=this.getSelectedIndex(); |
16 |
returnjQuery(this).get(0).options[index].text; |
21 |
jQuery.fn.getSelectedValue=function(){ |
25 |
returnjQuery(this).val(); |
29 |
jQuery.fn.setSelectedValue=function(value){ |
30 |
jQuery(this).get(0).value=value; |
34 |
jQuery.fn.setSelectedText=function(text){ |
36 |
var count=this.size(); |
37 |
for(var i=0;i<count;i++){ |
38 |
if(jQuery(this).get(0).options[i].text==text){ |
39 |
jQuery(this).get(0).options[i].selected=true; |
49 |
jQuery.fn.setSelectedIndex=function(index){ |
50 |
var count=this.size(); |
51 |
if(index>=count||index<0){ |
54 |
jQuery(this).get(0).selectedIndex=index; |
58 |
jQuery.fn.isExistItem=function(value){ |
60 |
var count=this.size(); |
61 |
for(var i=0;i<count;i++){ |
62 |
if(jQuery(this).get(0).options[i].value==value){ |
70 |
jQuery.fn.addOption=function(text,value){ |
71 |
if(this.isExistItem(value)){ |
74 |
jQuery(this).get(0).options.add(newOption(text,value)); |
78 |
jQuery.fn.removeItem=function(value){ |
79 |
if(this.isExistItem(value)){ |
80 |
var count=this.size(); |
81 |
for(var i=0;i<count;i++){ |
82 |
if(jQuery(this).get(0).options[i].value==value){ |
83 |
jQuery(this).get(0).remove(i); |
92 |
jQuery.fn.removeIndex=function(index){ |
93 |
var count=this.size(); |
94 |
if(index>=count||index<0){ |
97 |
jQuery(this).get(0).remove(index); |
101 |
jQuery.fn.removeSelected=function(){ |
102 |
var index=this.getSelectedIndex(); |
103 |
this.removeIndex(index); |
106 |
jQuery.fn.clearAll=function(){ |
107 |
jQuery(this).get(0).options.length=0; |
该文章在 2012/2/3 0:56:08 编辑过