Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
页面加载时在Javascript/Jquery中对引导模式体元素进行排序_Javascript_Jquery_Html_Bootstrap Modal - Fatal编程技术网

页面加载时在Javascript/Jquery中对引导模式体元素进行排序

页面加载时在Javascript/Jquery中对引导模式体元素进行排序,javascript,jquery,html,bootstrap-modal,Javascript,Jquery,Html,Bootstrap Modal,我正在处理一个提琴,我想从引导模式中对多行进行排序(第1行有def并分配计算机部分,第2行有abc并分配计算机部分,等等) 此时,行未在模式中排序。我用来创建模式的HTML/引导代码是: <div class="row-computerlabel form-group clearfix"> <div class="editcomputerlabel col-sm-5">abc</div> <div class="assigncomputerl

我正在处理一个提琴,我想从引导模式中对多行进行排序(第1行有def并分配计算机部分,第2行有abc并分配计算机部分,等等)

此时,行未在模式中排序。我用来创建模式的HTML/引导代码是:

<div class="row-computerlabel form-group clearfix">
   <div class="editcomputerlabel col-sm-5">abc</div>
   <div class="assigncomputerlabel col-sm-5">
      <div class="btn-group bootstrap-select show-tick computerlabelscomputerselector">
         <button type="button" class="btn dropdown-toggle btn-default" data-toggle="dropdown" title="Assign a computer"><span class="filter-option pull-left">Assign a computer</span>&nbsp;<span class="bs-caret"><span class="caret"></span></span></button>
         <div class="dropdown-menu open">
            <ul class="dropdown-menu inner" role="menu"></ul>
         </div>
         <select class="computerlabelscomputerselector selectpicker" multiple="" title="Assign a computer" tabindex="-98"></select>
      </div>
   </div>
   <div class="deletecomputerlabel col-sm-2"><button class="btn btn-link btn-delete" data-task="deletelabel" title="Delete group" type="button"><i class="fa fa-trash-o"></i></button></div>
</div>

abc
分配计算机
    问题陈述:


    我想知道我需要在上面添加什么简单的Javascript或Jquery代码,以便对引导模式中的所有内容进行排序,这意味着当页面加载时,abc、def、jkl文本应该首先与指定的计算机一起显示在小提琴中。

    您可以使用Javascript的排序功能

    jQuery

     $(document).ready(function(){
      var rowComputer = $('.row-computerlabel');
    
        rowComputer.sort(function(a,b){
            var label1 = $(a).children('.editcomputerlabel').text();
            var label2 = $(b).children('.editcomputerlabel').text();
                return label1 >= label2;
        });
        rowComputer.appendTo('#computerlabeltable');
    });
    
    这段代码非常简单。您在
    行计算机中有所有行的
    变量

    在数组上应用sort函数,需要指定排序条件(这里需要按字母顺序排序)

    最后,将包含div中的行的数组追加到所有行中

    jsFiddle


    这是一个jFiddle链接:

    我已经编辑了fiddle,它应该是这样的,因为它有3个子元素?目前你只使用了
    editcomputerlabel
    。对不起,John,我无法回答你。不需要,sort函数使用2个参数。如果您有2个元素要比较或100个元素,它将起作用。我使用了editcomputerlabel,因为这就是你想要比较的。对于每一行计算机标签,sort函数使用其editcomputerlabel类对其进行排序。