首页 技术 正文
技术 2022年11月17日
0 收藏 847 点赞 4,659 浏览 1751 个字

根据option的id属性,修改text值


  $("#sel_div .select_class option[id='-选择省-']").text(data.province).attr("selected",true);
$("#sel_div .select_class option[id='-选择市-']").text( data.city).attr("selected",true);
$("#sel_div .select_class option[id='-选择区-']").text( data.area).attr("selected",true);
$("#sel_div .select_class option[id='-选择街-']").text( data.street).attr("selected",true);
获取多个select(使用class属性,切值相同)下的所有option的text值

 $("#sel_div .select_class option").each(function(){ //遍历所有option标签       var text = $(this).text(); //获取option的text
alert(text);//显示的是当前这个option的text值
   if(txt == "选择省")
$("#sel_div .select_class option[id='-选择省-']").text(data.province).attr("selected",true);
if(txt == "选择市")
$("#sel_div .select_class option[id='-选择市-']").text( data.city).attr("selected",true);
if(txt == "选择区")
10 $("#sel_div .select_class option[id='-选择区-']").text( data.area).attr("selected",true);
11 if(txt == "选择街")
$("#sel_div .select_class option[id='-选择街-']").text( data.street).attr("selected",true); });

如果select中间没有级联关系,那么所有的option都已经加载,可以使用下面的方法显示查询出来的数据

$("#sel_div .select_class option[id="+data.province+"]").attr("selected",true);
$("#sel_div .select_class option[id="+data.city+"]").attr("selected",true);
$("#sel_div .select_class option[id="+data.area+"]").attr("selected",true);
$("#sel_div .select_class option[id="+data.street+"]").attr("selected",true);

另一种获取所有option的方法,相当于将所有text拼成字符串,把每个字符存进map中

var map = $("#sel_div .select_class option").map(function(){
alert($(this).text());//显示单个option的text text1
return $(this).text();
}).get().join(",");alert(map);//显示的是 text1,text2,text3
alert(map[0]);//显示 t
在上面的基础上进行改进,使用array数组存放查询出来的数据,在使用for循环可以对数据进行操作
 var array = new Array();
$("#leaf .form-control option").map(function(){
array.push($(this).text());
})
for(var i = 0; i < array.length; i ++ ){
alert(array[i]);//显示每个option的text text1,text2,text3
}

 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,136
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,300