Home  >  Article  >  Web Front-end  >  Example tutorial of jQuery selecting drop-down list

Example tutorial of jQuery selecting drop-down list

零下一度
零下一度Original
2017-06-29 10:07:291102browse

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>
</form>

The above is the detailed content of Example tutorial of jQuery selecting drop-down list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn