select控件获取text值示例代码

来源:互联网 发布:内核源码的配置文件 编辑:程序博客网 时间:2024/06/16 02:51
<html><head>  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body>   <nav title="首页">   </nav>   <div  width="100%" height="100%">     <select id="select" value="" width="100" >   </select>   </div></body><script>    var index = 0;    //原始数据源    var items = [{"id":"01","city":"上海"},{"id":"02","city":"北京"},                 {"id":"03","city":"广州"},{"id":"04","city":"深圳"},                 {"id":"05","city":"杭州"},{"id":"06","city":"南京"}];    var selcetItems = new Array();    for(var i = 0; i < items.length; i ++){                var item = {};        item.text = items[i].city;        item.value = items[i].id+"_"+items[i].city;        selcetItems.push(item);    }               select.setItems(selcetItems);        select.addEvent("onChange",function(oldValue,newValue){       if($M.isIOS){          log(newValue)          var arr = newValue.split("_");          alert(arr[1])       }       else       {         if(index>0){          log(newValue)          var arr = newValue.split("_");          alert(arr[1])         }         index ++;        }     })    </script></html>

0 0
原创粉丝点击