JQuery - 多选选项 [英] JQuery - Multiple Select Options

查看:27
本文介绍了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天全站免登陆