获取下拉框选中的label


1,如何获取下拉框选中的文本(不是值)呢?

Js代码   收藏代码
  1. var selectedIndex = $houseBuilding.get(0).selectedIndex;  
  2. var selectedOption = $houseBuilding.get(0).options[selectedIndex];  
  3. var selectHouse = selectedOption.label;  
  4. if (!selectHouse) {  
  5.     selectHouse = selectedOption.text;  
  6. }  

 


抽取为一个js方法:

Js代码   收藏代码
  1. /** 
  2.  * select component 
  3.  */  
  4. com.whuang.hsj.getSelectedOptionLabel = function(selectObj) {  
  5.     if (typeof selectObj == 'string') {  
  6.         selectObj = com.whuang.hsj.$$one(selectObj);  
  7.         if(selectObj==null ||selectObj==undefined){  
  8.             selectObj=com.whuang.hsj.$$id(selectObj);  
  9.         }  
  10.     }  
  11.     var selectedIndex = selectObj.selectedIndex;  
  12.     if (selectedIndex >= 0) {// omit the first option  
  13.         var selectOption = selectObj.options[selectedIndex];  
  14.         /*if ("textContent" in selectOption) {// textContent is specific to 
  15.             // Internet explorer and firefox has 
  16.             // no this attribute 
  17.             return selectOption.textContent; 
  18.         } else { 
  19.             return selectOption.label; 
  20.         }*/  
  21.         return selectOption.textContent || selectOption.label || selectedOption.text;  
  22.   
  23.     } else {  
  24.         return "";  
  25.     }  
  26.   
  27. };  

 

伦理片 http://www.dotdy.com/

2,应用

Js代码   收藏代码
  1. if (data.result == 1) {  
  2.                toast_hwShortCenter("投票成功");  
  3.            } else if (data.result == 2) {  
  4.                toast_hwShortCenter("您还没有登录");  
  5.                window.user = null;  
  6.                window.sessionId = null;  
  7.            } else if (data.result == 3) {  
  8.                toast_hwShortCenter("您已经投票过");  
  9.                 
  10.                alert('目前 "' + com.whuang.hsj.getSelectedOptionLabel($houseBuilding.get(0)) + '" 总投票数为:' + data.voteCount);  
  11.            } else {  
  12.                toast_hwShortCenter('未知错误');  
  13.            }  

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值