javascript jQuery UI 可在选择选项上排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11134417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:09:49  来源:igfitidea点击:

jQuery UI sortable on select options

javascriptjqueryjquery-uijquery-ui-sortable

提问by user1038814

I'm trying to get jQuery UI default sortable to work on options in a select multi list box but can't seem to get it working. Can this work with a select option? I've only seen examples with <li>everywhere.

我正在尝试使 jQuery UI 默认可排序以处理选择多列表框中的选项,但似乎无法使其正常工作。这可以与选择选项一起使用吗?我只见过<li>随处可见的例子。

Here's my JavaScript:

这是我的 JavaScript:

$(function() {
    $( "#secondSelectms2side__dx" ).sortable();
    $( "#secondSelectms2side__dx" ).disableSelection();
});

And the HTML:

和 HTML:

<select title="" name="secondSelectms2side__dx" id="secondSelectms2side__dx" size="8" multiple="multiple">
    <option value="4">asdsdsds</option>
    <option value="10">bsdsdsdsd</option>
    <option value="2">csdsdsds</option>
</select>?

My code is on jsFiddle:

我的代码在 jsFiddle 上:

http://jsfiddle.net/noscirre/DRUPe/

http://jsfiddle.net/noscirre/DRUPe/

采纳答案by Tats_innit

Workind demofor select options sorting using multiselect js widget: http://jsfiddle.net/QRv6d/9/

使用多选 js 小部件进行选择选项排序的Workind 演示http: //jsfiddle.net/QRv6d/9/

good link: https://github.com/yanickrochon/jquery.uix.multiselecthttp://quasipartikel.at/2009/05/10/jqueryui-multiselect/&http://quasipartikel.at/multiselect/

好的链接:https: //github.com/yanickrochon/jquery.uix.multiselect http://quasipartikel.at/2009/05/10/jqueryui-multiselect/ & http://quasipartikel.at/multiselect/

please note: I cannot find any simple sortable implementation of sortable() with select boxeshence using this multiselect plugin and as you can see in demo it does work :)you can use it according to your need. full HTML is in js fiddle.

请注意:我找不到 sortable() 的任何简单的可排序实现,select boxes因此使用此多选插件,正如您在演示中看到的那样,它确实有效,:)您可以根据需要使用它。完整的 HTML 在 js 中。

Hope this helps,

希望这可以帮助,

scriptsource

脚本

  <script type="text/javascript" src="http://quasipartikel.at/multiselect/js/ui.multiselect.js"></script>

code

代码

  $(function(){

            $(".multiselect").multiselect();

        });?

HTML

HTML

<select id="countries" class="multiselect" multiple="multiple">

    <option value="AUT" selected="selected">Austria</option>
    <option value="DEU" selected="selected">Germany</option>

    <option value="NLD" selected="selected">Netherlands</option>

    <option value="USA" selected="selected">United States</option>


  </select>

Image

图片

enter image description here

在此处输入图片说明

回答by Ashley Raiteri

This is what you need. You'll have to do some extra work if you want to customize the stlying to 'look' like a traditional select box. I'm integrating this with simple_form and will post the code here.

这就是你所需要的。如果您想将 stlying 自定义为“看起来”像传统的选择框,则必须做一些额外的工作。我正在将它与 simple_form 集成,并将在此处发布代码。

https://github.com/thgreasi/ui-sortable-multiselection

https://github.com/thgreasi/ui-sortable-multiselection