将Jquery UI Sortable转换为表而不是ul

时间:2015-01-11 09:23:26

标签: javascript jquery html css jquery-ui

我正在尝试将Jquery UI drag-gable从ul转换为表但失败了。这是Jquery UI链接http://jqueryui.com/sortable/#connect-lists。这是我试过的那么快,

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Sortable - Connect lists</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
    table td {
      padding: 10px;
    }
  </style>
  <script>
  $(function() {
    $( ".sortable" ).sortable({
      //connectWith: ".sortable"
    }).disableSelection();
  });
  </script>
</head>
<body>
<table border="1">
  <tr>
    <th>Name</th>
    <th>Task1</th>
    <th>Task2</th>
  </tr>
<tr>
  <td>
    <span class="ui-state-default sortable">Item 11</span>
    <span class="ui-state-default sortable">Item 12</span>
    <span class="ui-state-default sortable">Item 13</span>
  </td>
  <td>
    <span class="ui-state-default sortable">Item 11</span>
    <span class="ui-state-default sortable">Item 12</span> 
  </td>
  <td>
    <span class="ui-state-default sortable">Item 21</span>    
  </td>
</tr>
<tr>
  <td>
    <span class="ui-state-default sortable">Item 31</span>
    <span class="ui-state-default sortable">Item 32</span>  
  </td>
  <td>
    <span class="ui-state-default sortable">Item 41</span>    
  </td>
  <td>
    <span class="ui-state-default sortable">Item 51</span>
    <span class="ui-state-default sortable">Item 52</span>
    <span class="ui-state-default sortable">Item 53</span>
  </td>
</tr>

  </table>
</body>
</html>

这是JsBin链接http://jsbin.com/fucasipaje/1/ 但是拖放不起作用。

1 个答案:

答案 0 :(得分:1)

试试这个

  $(function() {
    $( "#table td" ).sortable({
      connectWith: "#table td"
    }).disableSelection();
  });

Example