Показать сообщение отдельно
  #2 (permalink)  
Старый 29.12.2014, 04:22
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,135

Sanu0074,

<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <meta charset="utf-8">


  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <script>
     $(function(){
      var arr = $.makeArray( $("tbody tr") );;
       arr.sort(function(a, b) {
         a = $(a).data('sort')!== void(0)? +$(a).data('sort'):-1 ;
         b = $(b).data('sort')!== void(0)? +$(b).data('sort') : -1 ;
         return b - a
      });
    $( arr ).prependTo("tbody");
    alert($("body").html())
});


  </script>
</head>

<body>
<table>
  <tbody>
      <tr>
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="8">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="12">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="2">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="7">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="0">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
      <tr data-sort="0">
          <th>cell 1</th>
          <th>cell 2</th>
      </tr>
  </tbody>
</table>


</body>

</html>
Ответить с цитированием