Sort Table Rows according to table data

前端 未结 3 569
梦谈多话
梦谈多话 2021-01-13 16:49

For example, I have a code:

3条回答
  •  走了就别回头了
    2021-01-13 17:08

    Have a look at Sorting - we're doing it wrong. A simple jQuery plugin for sorting stuff is available here.


    some notes on your code:

    // you're binding a document ready event within a function call? 
    // looks the wrong way 'round, to me
    function sortTheTable(){
        $(function() {
            // 1) you probably want to use .detach() over .remove()
            // 2) "tr:has(.price)" will match ALL table rows 
            // containing an element with the class .price
            // even if they're children of different 
name price
s! // 3) $('.selector') is already "an array", at least it's sortable right away. // there's no need for $.makeArray() here var elems = $.makeArray($('tr:has(.price)').remove()) elems.sort(sortNum) // "#information" is a sufficient (and more efficient) selector, $('table#information').append($(elems)); }); }

提交回复
热议问题