jquery多重选择从两个选择变成一个选择?

发布于 2024-08-24 03:19:46 字数 1594 浏览 3 评论 0原文

我试图弄清楚如何创建一个多选表单,该表单具有两个选择,允许您将条件移至第三个选择。我确实看过:

http://www.quasipartikel.at/multiselect/

/ /http://www.erichynds.com/jquery/ jquery-multiselect-plugin-with-themeroller-support/ (我是新人,所以我只能发布一个链接...:-))

但它们看起来都只允许一对一选择,而不是我想要的二对一选择实施...

像这样:

<!-- user selects multiple values from this and the selected options are moved to third select onclick -->
<select id="select1" name="select1[]" multiple="multiple">
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
</select>

<!-- user also selects multiple values from this and the selected options are moved to third select onclick -->
<select id="select2" name="select2[]" multiple="multiple">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
</select>

<!-- this is the target for the previously selected options -->
<select id="target" name="target[]" disabled>
<!-- all of the selected options from select1 and select2 are placed here onclick -->
</select>

这可能吗?有谁有一个有效的示例,或者说明此类事情的链接?

I'm trying to figure out how to create a multiselect form that has two selects that allow you to move criteria into a third select. I did take a look at:

http://www.quasipartikel.at/multiselect/

and

//http://www.erichynds.com/jquery/jquery-multiselect-plugin-with-themeroller-support/
(I'm new, so I can only post one link... :-) )

but they both look like they only allow a one-to-one selection, rather than the two-to-one that I'd like to implement...

Something like this:

<!-- user selects multiple values from this and the selected options are moved to third select onclick -->
<select id="select1" name="select1[]" multiple="multiple">
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
</select>

<!-- user also selects multiple values from this and the selected options are moved to third select onclick -->
<select id="select2" name="select2[]" multiple="multiple">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
</select>

<!-- this is the target for the previously selected options -->
<select id="target" name="target[]" disabled>
<!-- all of the selected options from select1 and select2 are placed here onclick -->
</select>

Is this possible? Does anyone have a working example, or a link that illustrates this kind of thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆沫 2024-08-31 03:19:46

您需要一个 id 为“add”的按钮,

进行选择并点击添加按钮

,并将此代码附加到按钮上

$('#add').click(function() {  
 return !$('#select1 option:selected,#select2 option:selected').appendTo('#target');  
});

You need a button with an id of 'add"

make selections hit the add button

with this code attached to the button

$('#add').click(function() {  
 return !$('#select1 option:selected,#select2 option:selected').appendTo('#target');  
});
我ぃ本無心為│何有愛 2024-08-31 03:19:46

您可以根据您的需要进行定制:

$(function() {
    $("#select1, #select2").change(function() {
        $("#target").append($(":selected", $(this)).remove());
    });
});

它从下拉列表中查找选定的项目,将其删除,然后将其附加到目标下拉列表中。

You may be able to tailor this to your needs:

$(function() {
    $("#select1, #select2").change(function() {
        $("#target").append($(":selected", $(this)).remove());
    });
});

It finds the selected item from the dropdown, removes it, and appends it to the target dropdown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文