jQuery选中下拉列表的实例教程
来源:懂视网
责编:小采
时间:2020-11-27 20:18:01
jQuery选中下拉列表的实例教程
jQuery选中下拉列表的实例教程:jQuery部分:$("#form1 select").change(function () { var s=[]; $("#form1 select :selected").each(function () { var temp=$(this).html(); s.push(temp);//注意这里不能使方括号 }
导读jQuery选中下拉列表的实例教程:jQuery部分:$("#form1 select").change(function () { var s=[]; $("#form1 select :selected").each(function () { var temp=$(this).html(); s.push(temp);//注意这里不能使方括号 }

jQuery部分:
$("#form1 select").change(function () {
var s=[];
$("#form1 select :selected").each(function () {
var temp=$(this).html();
s.push(temp);//注意这里不能使方括号
})
var xx=s.join();//默认中间加逗号
$("div:last").html(xx);
})
html部分:
<form ic="form1">
下拉列表1:<br/>
<select name="test" multiple="multiple" style="height:100px">
<option>浙江</option>
<option selected="selected">湖南</option>
<option>北京</option>
<option selected="selected">天津</option>
<option>广州</option>
<option>湖北</option>
</select>
<br/><br/>
下拉列表2:<br/>
<select name="test2" >
<option>浙江</option>
<option>湖南</option>
<option selected="selected">北京</option>
<option>天津</option>
<option>广州</option>
<option>湖北</option>
</select>
<br/><br/>
<div></div>
jQuery选中下拉列表的实例教程
jQuery选中下拉列表的实例教程:jQuery部分:$("#form1 select").change(function () { var s=[]; $("#form1 select :selected").each(function () { var temp=$(this).html(); s.push(temp);//注意这里不能使方括号 }