jQueryMoveTr.html
代码如下:
jquery-rlutil-1.6.2.js代码如下:
if(objVal == firstTrVal){
/判断是否在把第一行向上移/
return;
}else{
prevMoveTrOpra(obj,td_self_id);
/调用上移操作方法/
}
}
/上移操作/
function prevMoveTrOpra(obj,td_self_id){
var $jqObj = jQuery(obj).parent().parent().clone(); /获得并复制本身tr的信息/ var $jqSublObj = jQuery(obj).parent().parent().prev();<span style="font-family: Arial,Helvetica,sans-serif;"> /获得上一个tr的信息/ $jqSublObj.find("."+td_self_id+" input:nth-child(1)").val(Number($jqSublObj.find("."+td_self_id+" input:nth-child(1)").val())+1);<span style="font-family: Arial,sans-serif;"> /把上一个tr序号加1/ jQuery(obj).parent().parent().html("").append($jqSublObj.html()); <span style="font-family: Arial,sans-serif;"> /把本身tr清空并插入上一个信息/
$jqObj.find("."+td_self_id+" input:nth-child(1)").val(Number($jqObj.find("."+td_self_id+" input:nth-child(1)").val())-1); /把本身tr序号减1/ $jqSublObj.html("").append($jqObj.html()); /把上一个tr清空并插入临时保存的tr信息/
$jqObj.remove(); /删除复制的多余jQuery对象/}
/下移指令/ function nextMoveTrCommand(obj,td_self_id){
var $jqLastTr = jQuery("#"+table_self_id+" tr:last-child"); <span style="font-family: Arial,sans-serif;">/获得最后一个tr的对象/ var lastTrVal = $jqLastTr.find("."+td_self_id+" input:nth-child(1)").val(); /获得最后一个tr的序号/ var objVal = jQuery(obj).parent().parent().find("."+td_self_id+" input:nth-child(1)").val(); <span style="font-family: Arial,sans-serif;"> /获得本身tr的序号/ if(objVal == lastTrVal){ <span style="font-family: Arial,sans-serif;">/判断是否想把最后一行往下移/ return;
}else{
nextMoveTrOpra(obj,td_self_id); <span style="font-family: Arial,sans-serif;">/调用下移操作方法/<span style="font-family: Arial,sans-serif;"><span style="white-space:pre"> }}
/下移操作/ function nextMoveTrOpra(obj,td_self_id){
var $jqObj = jQuery(obj).parent().parent().clone(); <span style="font-family: Arial,sans-serif;"> /获得并复制本身tr的信息/ var $jqSiblObj = jQuery(obj).parent().parent().next(); <span style="font-family: Arial,sans-serif;"> /获得下一个tr的信息/ $jqSiblObj.find("."+td_self_id+" input:nth-child(1)").val(Number($jqSiblObj.find("."+td_self_id+" input:nth-child(1)").val())-1); <span style="font-family: Arial,sans-serif;"> /把下一个tr序号减1/<span style="font-family: Arial,sans-serif;">
jQuery(obj).parent().parent().html("").append($jqSiblObj.html()); <span style="font-family: Arial,sans-serif;">/把本身tr清空并插入下一个tr信息/<span style="font-family: Arial,sans-serif;">
$jqObj.find("."+td_self_id+" input:nth-child(1)").val(Number($jqObj.find("."+td_self_id+" input:nth-child(1)").val())+1); <span style="font-family: Arial,sans-serif;">/把本身tr序号加1/<span style="font-family: Arial,sans-serif;">
$jqSiblObj.html("").append($jqObj.html()); <span style="font-family: Arial,sans-serif;">/把下一个tr清空并插入临时保存的tr信息/<span style="font-family: Arial,sans-serif;">
$jqObj.remove(); /删除复制的多余jQuery对象/ }
jswension.HTML代码如下:
<script type="text/javascript">
[color=green]/onclick=prevMoveTrCommand(this,'td_num'); 这个地方千万不要带空格,否则乱码/[/color]
jQuery(document).ready(function(){
var str = "";
str += "<tr>";
str += "
str += "<td>aaaaaaaaaa</td>";
str += "<td>@@@@@@@</td>";
str += "
str += " <input type='button' name='btn2' value='↓' onclick=nextMoveTrCommand(this,'td_num'); /></td>";
str += "<td>注释1</td>";
str += "</tr>";
str += "<tr>";
str += "
str += "<td>bbbbbbbbbbbbb</td>";
str += "<td>#########</td>";
str += "
str += "<td>注释2</td>";
str += "</tr>";
str += "<tr>";
str += "
str += "<td>cccccccccccc</td>";
str += "<td>$$$$$$$$$$$$</td>";
str += "
str += "<td>注释3</td>";
str += "</tr>";
str += "<tr>";
str += "
str += "<td>ddddddddddddd</td>";
str += "<td>&&&&&&&&&&&&&</td>";
str += "
str += "<td>注释4</td>";
str += "</tr>";
str += "<tr>";
str += "
str += "<td>eeeeeeeeeeeeee</td>";
str += "<td>***</td>";
str += "
str += "<td>注释5</td>";
str += "</tr>";
$("#show_table_id").html(str);
});