jqueryテーブル追加削除行操作


<html>
<head>
<title>jQuery       、                CsrCode.Cn</title>
<script language="javascript" src="js/jquery.js"></script>
</head>
<body>
<a href="#" onclick="add_line();">    </a>  <a href="#" onclick="remove_line();">    </a>  <a href="#" onclick="up_exchange_line()">  </a>  <a href="#" onclick="down_exchange_line()">  </a>
<table>
<tr><td>  </td><td>    </td><td>    </td><td>    </td></tr>
</table>
<table id="content">
</table>
<script language="javascript">
var currentStep=0;
var max_line_num=0;
function add_line(){
  max_line_num=$("#content tr:last-child").children("td").html();
  if(max_line_num==null) {
    max_line_num=1;
  }
  else{
    max_line_num=parseInt(max_line_num);
 max_line_num+=1;
  }
  $('#content').append("<tr id='line"+max_line_num+"' onclick='lineclick(this);'><td>"+max_line_num+"</td><td>    "+max_line_num+"</td><td>      "+max_line_num+"</td><td>      </td></tr>");
}
function remove_line(){  
  $("#content tr").each(
    function(){
   var seq=parseInt($(this).children("td").html());
   if(seq==currentStep) $(this).remove();
   if(seq>currentStep) $(this).children("td").each(function(i){if(i==0)$(this).html(seq-1);});
 }
  );
  currentStep=0;
}
function up_exchange_line(){ 
  if(currentStep==0){
    alert('     !');
 return false;
  }
  if(currentStep<=1){
     alert('    !');
  return false;
  }
  var upStep=currentStep-1;
  //    
  $('#line'+upStep+" td:first-child").html(currentStep);
  $('#line'+currentStep+" td:first-child").html(upStep);
  //       
  var upContent=$('#line'+upStep).html();
  var currentContent=$('#line'+currentStep).html();
  $('#line'+upStep).html(currentContent);
  //           
  $('#line'+currentStep).html(upContent);  
  $('#content tr').each(function(){$(this).css("background-color","#ffffff");});
  $('#line'+upStep).css("background-color","yellow"); 
  currentStep=upStep;
}
function down_exchange_line(){
 if(currentStep==0){
    alert('     !');
 return false;
 }
 if(currentStep>=max_line_num){
     alert('    !');
  return false;
  }
  var nextStep=parseInt(currentStep)+1;
  //    
  $('#line'+nextStep+" td:first-child").html(currentStep);
  $('#line'+currentStep+" td:first-child").html(nextStep);
  //       
  var nextContent=$('#line'+nextStep).html();
  var currentContent=$('#line'+currentStep).html();
  $('#line'+nextStep).html(currentContent);
  //           
  $('#line'+currentStep).html(nextContent);  
  $('#content tr').each(function(){$(this).css("background-color","#ffffff");});
  $('#line'+nextStep).css("background-color","yellow"); 
  currentStep=nextStep;
}
function lineclick(line){
   $('#content tr').each(function(){$(this).css("background-color","#ffffff");});
   var seq=$(line).children("td").html();
   $(line).css("background-color","yellow");
   currentStep=seq;
}
$(document).ready(function(){
	$('p').dbclick(function(){
		alert("dbclick");
	});
});
</script>
<p>kdkdkdd</p>
</body>
</html>

<br>         ,       <br><hr><p align="center"><font color=black>     <a href="http://www.CsrCode.cn" target="_blank">      </a> CsrCode.Cn       ,         ,      。</font></p>