联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

JQuery-tableDnD 拖拽的基本使用介绍 - Web前端

作者:98wpeu发布时间:2026-07-24分类:网页前端技术浏览:1


导读:在页面上导入JS复制代码代码如下:JQuery-1.3.2.min.jsjQuery.tablednd_0_5.js注意:一定要先导入jquery-1.3.2.min.js否则...
在页面上导入JS
复制代码 代码如下:
JQuery-1.3.2.min.js
jQuery.tablednd_0_5.js
注意:一定要先导入jquery-1.3.2.min.js 否则出错。

·建table
复制代码 代码如下:
<TABle id="table-1" cellspacing="0" cellpadding="2">
    <tr id="1"><td>1</td><td>One</td><td>some text</td></tr>
    <tr id="2"><td>2</td><td>Two</td><td>some text</td></tr>
    <tr id="3"><td>3</td><td>Three</td><td>some text</td></tr>
    <tr id="4"><td>4</td><td>Four</td><td>some text</td></tr>
    <tr id="5"><td>5</td><td>Five</td><td>some text</td></tr>
    <tr id="6"><td>6</td><td>Six</td><td>some text</td></tr>
</table>

·插入js代码
复制代码 代码如下:
<scripttype="text/javascript">
  $(document).ready(function() {
        $("#table-1").tableDnD();
    });
 </script>

·ok。
·例子
复制代码 代码如下:
<%
    string path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    pageContext.setAttribute("basePath", basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
       <script type="text/JavaScript"
           src="${basePath}common/js/jquery-1.3.2.min.js"></script>
       <script type="text/Javascript"
           src="${basePath}common/js/JQuery.tablednd_0_5.js"></script>
       <style type="text/CSS">
.aa {
    background: #00FF99
}

.bb {
    background: #0066FF
}
</style>

<script type="text/javascript">

  $(document).ready(function() { 
  color();
        $("#table-1").tableDnD({
           onDrop:function(table,row){
           var b = $(row).children().eq(0).text();
           color();
            }
        });

    });

    function color()
    {
       var tbody = $("table[id='table-1'] tr");
       tbody.each(function(index){
          var cc = index%2;
          if(0==cc)
            {
            $(this).removeclass();
            $(this).addClass("aa");
            }
           else
           {
           $(this).removeClass();
            $(this).addClass("bb");
           }
       });
    }
 </script>
    </head>

    <body>
       <table id="table-1" cellspacing="0" cellpadding="2">
           <tr id="1"><td>1</td><td>One</td><td>some text</td></tr>
           <tr id="2"><td>2</td><td>Two</td><td>some text</td></tr>
           <tr id="3"><td>3</td><td>Three</td><td>some text</td></tr>
           <tr id="4"><td>4</td><td>Four</td><td>some text</td></tr>
           <tr id="5"><td>5</td><td>Five</td><td>some text</td></tr>
           <tr id="6"><td>6</td><td>Six</td><td>some text</td></tr>
       </table>

    </body>
</html>

标签:拖拽WebtableDnDJQuery


网页前端技术排行
最近发表
网站分类
标签列表