JQuery-tableDnD 拖拽的基本使用介紹
更新時(shí)間:2013年07月04日 10:24:09 作者:
本篇文章是對(duì)JQuery-tableDnD拖拽的基本使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
在頁(yè)面上導(dǎo)入js
jquery-1.3.2.min.js
jquery.tablednd_0_5.js
注意:一定要先導(dǎo)入jquery-1.3.2.min.js 否則出錯(cuò)。
·建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代碼
<script type="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>
復(fù)制代碼 代碼如下:
jquery-1.3.2.min.js
jquery.tablednd_0_5.js
注意:一定要先導(dǎo)入jquery-1.3.2.min.js 否則出錯(cuò)。
·建table
復(fù)制代碼 代碼如下:
<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代碼
復(fù)制代碼 代碼如下:
<script type="text/javascript">
$(document).ready(function() {
$("#table-1").tableDnD();
});
</script>
·ok。
·例子
復(fù)制代碼 代碼如下:
<%
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>
您可能感興趣的文章:
- JQuery Dialog(JS 模態(tài)窗口,可拖拽的DIV)
- JQuery之拖拽插件實(shí)現(xiàn)代碼
- 簡(jiǎn)單的jquery拖拽排序效果實(shí)現(xiàn)代碼
- jQuery EasyUI API 中文文檔 - Draggable 可拖拽
- JQuery UI的拖拽功能實(shí)現(xiàn)方法小結(jié)
- jquery實(shí)現(xiàn)簡(jiǎn)單的拖拽效果實(shí)例兼容所有主流瀏覽器
- 如何使用jQuery Draggable和Droppable實(shí)現(xiàn)拖拽功能
- jQuery拖拽div實(shí)現(xiàn)思路
- jQuery手機(jī)瀏覽器中拖拽動(dòng)作的艱難性分析
- jquery實(shí)現(xiàn)鼠標(biāo)拖拽滑動(dòng)效果來(lái)選擇數(shù)字的方法
- jQuery實(shí)現(xiàn)html元素拖拽
相關(guān)文章
JQuery 傳送中文亂碼問(wèn)題的簡(jiǎn)單解決辦法
下面小編就為大家?guī)?lái)一篇JQuery 傳送中文亂碼問(wèn)題的簡(jiǎn)單解決辦法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
載入jQuery庫(kù)的最佳方法詳細(xì)說(shuō)明及實(shí)現(xiàn)代碼
網(wǎng)站開(kāi)發(fā)的項(xiàng)目中使用Google CDN的jQuery庫(kù)雖然加載速度很快,但調(diào)用本地服務(wù)器的庫(kù)才可以確保萬(wàn)無(wú)一失,接下來(lái)介紹載入jQuery庫(kù)的最佳方法,感興趣的朋友可以研究下2012-12-12
jQuery中的pushStack實(shí)現(xiàn)原理和應(yīng)用實(shí)例
這篇文章主要介紹了jQuery中的pushStack實(shí)現(xiàn)原理和應(yīng)用實(shí)例,pushStack是jQuery內(nèi)核中一個(gè)非常重要的函數(shù),許多jQuery內(nèi)部函數(shù)中都頻繁用到它,掌握這個(gè)函數(shù),有利于理解jQuery的運(yùn)行原理,需要的朋友可以參考下2015-02-02
淺析Bootstrip的select控件綁定數(shù)據(jù)的問(wèn)題
這篇文章主要介紹了淺析Bootstrip的select控件綁定數(shù)據(jù)的問(wèn)題 的相關(guān)資料,小編認(rèn)為非常具有參考價(jià)值,感興趣的朋友一起看下吧2016-05-05
jQuery實(shí)現(xiàn)表格行數(shù)據(jù)滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)表格行數(shù)據(jù)滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
jQuery調(diào)用AJAX時(shí)Get和post公用的亂碼解決方法實(shí)例說(shuō)明
js調(diào)用AJAX時(shí)Get和post的亂碼解決辦法以前有寫(xiě)過(guò)的但是使用js代碼比較繁瑣,下面與大家分享下使用jQuery該怎么解決,遇到類似情況的朋友可以參考下哈2013-06-06

