LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

jquery操作select

admin
2012年2月3日 0:56 本文热度 2498
1 //得到select项的个数
2 jQuery.fn.size=function(){
3 returnjQuery(this).get(0).options.length;
4 }
5
6 //获得选中项的索引
7 jQuery.fn.getSelectedIndex=function(){
8 returnjQuery(this).get(0).selectedIndex;
9 }
10
11 //获得当前选中项的文本
12 jQuery.fn.getSelectedText=function(){
13 if(this.size()==0)return"下拉框中无选项";
14 else{
15 var index=this.getSelectedIndex();
16 returnjQuery(this).get(0).options[index].text;
17 }
18 }
19
20 //获得当前选中项的值
21 jQuery.fn.getSelectedValue=function(){
22 if(this.size()==0)
23 return"下拉框中无选中值";
24 else
25 returnjQuery(this).val();
26 }
27
28 //设置select中值为value的项为选中
29 jQuery.fn.setSelectedValue=function(value){
30 jQuery(this).get(0).value=value;
31 }
32
33 //设置select中文本为text的第一项被选中
34 jQuery.fn.setSelectedText=function(text){
35 var isExist=false;
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;
40 isExist=true;
41 break;
42 }
43 }
44 if(!isExist){
45 alert("下拉框中不存在该项");
46 }
47 }
48 //设置选中指定索引项
49 jQuery.fn.setSelectedIndex=function(index){
50 var count=this.size();
51 if(index>=count||index<0){
52 alert("选中项索引超出范围");
53 }else{
54 jQuery(this).get(0).selectedIndex=index;
55 }
56 }
57 //判断select项中是否存在值为value的项
58 jQuery.fn.isExistItem=function(value){
59 var isExist=false;
60 var count=this.size();
61 for(var i=0;i<count;i++){
62 if(jQuery(this).get(0).options[i].value==value){
63 isExist=true;
64 break;
65 }
66 }
67 returnisExist;
68 }
69 //向select中添加一项,显示内容为text,值为value,如果该项值已存在,则提示
70 jQuery.fn.addOption=function(text,value){
71 if(this.isExistItem(value)){
72 alert("待添加项的值已存在");
73 }else{
74 jQuery(this).get(0).options.add(newOption(text,value));
75 }
76 }
77 //删除select中值为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);
84 break;
85 }
86 }
87 }else{
88 alert("待删除的项不存在!");
89 }
90 }
91 //删除select中指定索引的项
92 jQuery.fn.removeIndex=function(index){
93 var count=this.size();
94 if(index>=count||index<0){
95 alert("待删除项索引超出范围");
96 }else{
97 jQuery(this).get(0).remove(index);
98 }
99 }
100 //删除select中选定的项
101 jQuery.fn.removeSelected=function(){
102 var index=this.getSelectedIndex();
103 this.removeIndex(index);
104 }
105 //清除select中的所有项
106 jQuery.fn.clearAll=function(){
107 jQuery(this).get(0).options.length=0;
108 }

该文章在 2012/2/3 0:56:08 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved