jQuery-多个选择选项 [英] JQuery - Multiple Select Options

查看:114
本文介绍了jQuery-多个选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试抓取以下所有选中的内容,并用逗号将它们分开.代码如下:

I am trying to grab all selected items in the following select multiple and separate them by a comma. The code is below:

<select id="ps-type" name="ps-type" multiple="multiple" size="5">
    <option>Residential - Wall Insulation</option>
    <option>Residential - Attic /Crawl Space Insulation</option>
    <option>Residential - Foundation Insulation</option>
    <option>Residential - Exterior Roof System</option>
    <option>Commercial - Wall Insulation</option>
    <option>Commercial - Air Barrier System (Walltite)</option>
    <option>Commercial - Roof System</option>
</select>

我正在寻找的结果如下:

The result I am looking for is the following:

住宅-墙壁绝缘,商业-墙壁绝缘,...

Residential - Wall Insulation, Commercial - Wall Insulation, ...

推荐答案

您可以使用:selected选择器,并且将内联$.map()函数用作链的一部分.

You can use the :selected selector, and the inline $.map() function as part of your chain.

$("option:selected").map(function(){ return this.value }).get().join(", ");

这篇关于jQuery-多个选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆