您的位置:首页 > Web前端 > JQuery

多级联动,下拉列表取text及value值的两种方法(传统方法+JQuery方法)

2017-08-29 16:44 381 查看
//县级改变,取文本及value值
$("#s3").change(function (){
// 			  1:拿到select对象:
var  myselect=document.getElementById("s3");

// 			  2:拿到选中项的索引:
var index=myselect.selectedIndex ;  // selectedIndex代表的是你所选中项的index

// 			  3:拿到选中项options的value:
var aa=myselect.options[index].value;

// 			  4:拿到选中项options的text:
var bb=myselect.options[index].text;
alert(aa)
alert(bb)

// 				在此处,下列方法适用于单一下拉列表,
// 				多级联动的,每个select被选中的text值都会取一次,数据库字段不太合适,
// 				【省:湖北省】【市:湖北省武汉市】【县:湖北省武汉市xxx县】
// 				alert($('select option:selected').val());
// 				alert($('select option:selected').text());

})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: