经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » jQuery » 查看文章
jquery实现表格行拖动排序
来源:jb51  时间:2022/2/22 15:52:25  对本文有异议

本文实例为大家分享了jquery实现表格行拖动排序的具体代码,供大家参考,具体内容如下

引入JS

  1. <script src="jquery.min.js"></script>
  2. <script src="jquery-ui.min.js"></script>

html代码

  1. <!doctype html>
  2. <html>
  3. <head>
  4. ? ? <meta charset="UTF-8">
  5. ? ? <title>sortDemo</title>
  6. ? ? <script src="jquery.min.js"></script>
  7. ? ? <script src="jquery-ui.min.js"></script>
  8.  
  9. </head>
  10. <body>
  11.  
  12. <table id="dataTable" border="1" cellpadding="6" cellspacing="0" align="center" style="margin-top: 10px;border-color: #dddddd;border-style: solid;">
  13. ? ? <thead>
  14. ? ? ? ? <tr>
  15. ? ? ? ? ? ? <th>序号</th>
  16. ? ? ? ? ? ? <th>姓名</th>
  17. ? ? ? ? ? ? <th>年龄</th>
  18. ? ? ? ? </tr>
  19. ? ? </thead>
  20. ? ? <tbody>
  21. ? ? ? ? <tr>
  22. ? ? ? ? ? ? <td>1</td>
  23. ? ? ? ? ? ? <td>张三</td>
  24. ? ? ? ? ? ? <td>18</td>
  25. ? ? ? ? </tr>
  26. ? ? ? ? <tr>
  27. ? ? ? ? ? ? <td>2</td>
  28. ? ? ? ? ? ? <td>李四</td>
  29. ? ? ? ? ? ? <td>25</td>
  30. ? ? ? ? </tr>
  31. ? ? ? ? <tr>
  32. ? ? ? ? ? ? <td>3</td>
  33. ? ? ? ? ? ? <td>王五</td>
  34. ? ? ? ? ? ? <td>16</td>
  35. ? ? ? ? </tr>
  36. ? ? ? ? <tr>
  37. ? ? ? ? ? ? <td>4</td>
  38. ? ? ? ? ? ? <td>赵六</td>
  39. ? ? ? ? ? ? <td>30</td>
  40. ? ? ? ? </tr>
  41. ? ? ? ? <tr>
  42. ? ? ? ? ? ? <td>5</td>
  43. ? ? ? ? ? ? <td>田七</td>
  44. ? ? ? ? ? ? <td>20</td>
  45. ? ? ? ? </tr>
  46. ? ? </tbody>
  47. </table>
  48. <script type="text/javascript">
  49. ? ? $(function() {
  50. ? ? ? ? var fixHelper = function(e, ui) {
  51. ? ? ? ? ? ? ui.children().each(function() {
  52. ? ? ? ? ? ? ? ? $(this).width($(this).width());
  53. ? ? ? ? ? ? });
  54. ? ? ? ? ? ? return ui;
  55. ? ? ? ? };
  56.  
  57. ? ? ? ? $("#dataTable tbody").sortable({
  58. ? ? ? ? ? ? cursor: "move",
  59. ? ? ? ? ? ? helper: fixHelper,
  60. ? ? ? ? ? ? axis:"y",
  61. ? ? ? ? ? ? start:function(e, ui){
  62. ? ? ? ? ? ? ? ? ui.helper.css({"background":"#fff"});
  63. ? ? ? ? ? ? ? ? return ui;
  64. ? ? ? ? ? ? }
  65. ? ? ? ? });
  66. ? ? ? ? $( "#sortable" ).disableSelection();
  67. ? ? });
  68.  
  69. </script>
  70. </body>
  71. </html>

效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号