检测模块的任务---上下移动单元格

来源:互联网 发布:山海经是真的吗 知乎 编辑:程序博客网 时间:2024/04/30 09:46

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
test114
</title>
</head>
<body bgcolor="#ffffff">
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
 function Changeit(startRow,endRow,col,flag)    //交换表中的两列,需要遍历每一行,然后交换每一个元素。因为没有表列对象。
{
   if(flag=='down')
   {
    if(document.all.ExTable.rows[endRow+1].cells[col].firstChild.value!="")
    {alert("请先移动下面的单元格");return;}
    else
   {
   for (var i=endRow;i>=startRow;i--)
   document.all.ExTable.rows[i+1].cells[col].firstChild.value=document.all.ExTable.rows[i].cells[col].firstChild.value;
   document.all.ExTable.rows[i+1].cells[col].firstChild.value="";
  
   }
   }
else

if((document.all.ExTable.rows[startRow].cells[col].firstChild.value!="")&&(document.all.ExTable.rows[startRow-1].cells[col].firstChild.value==""))
{
for (var i=startRow;i<=endRow;i++)
document.all.ExTable.rows[i-1].cells[col].firstChild.value=document.all.ExTable.rows[i].cells[col].firstChild.value;
document.all.ExTable.rows[i-1].cells[col].firstChild.value="";
return true;
}
if(document.all.ExTable.rows[startRow].cells[col].firstChild.value=="")
{
alert("不能用空单元格覆盖有值的单元格");return;
}
if(document.all.ExTable.rows[startRow-1].cells[col].firstChild.value!="")
{alert("你选择的起始行前面没有空单元格满足上移");return;}
}
}
function down()
{
  var startRow=Number(document.all('startext').value)-1;
  var endRow=Number(document.all('endtext').value)-1;
  var col=Number(document.all('col').value)-1;
if(col<0){alert("请输入列");  return;}
 if(startRow<0) {alert("请输入移动起始行");return;  }
 if(endRow<0)  {alert("请输入移动的结束行"); return;}
 if(startRow>endRow){alert("起始行应该小于结束行");return;}
Changeit(startRow,endRow,col,'down');
}
function up()
{
var startRow=Number(document.all('startext').value)-1;
  var endRow=Number(document.all('endtext').value)-1;
  var col=Number(document.all('col').value)-1;

 if(col<0){alert("请输入列");  return;}
 if(startRow<0) {alert("请输入移动起始行");return;  }
 if(endRow<0)  {alert("请输入移动的结束行"); return;}
 if(startRow>endRow){alert("起始行应该小于结束行");return;}
Changeit(startRow,endRow,col,'up');
}
</SCRIPT>
</head>
<body >
<p>对 第 <input type="text" name="col" value="" size="4"/> 列
从 第<input type="text" name="startext" value="" size="4"/> 行
&nbsp;到 第<input type="text" name="endtext" value="" size="4"/> 行
<input type="button" name="down" onclick="down()" value="下移" />
<input type="button" name="up" onclick="up()" value="上移" />
</p>
<p>
<table border=1 id="ExTable">
<tr>
<td  id="td1"><input type=text name="text1" value="haha"/></td>
<td  id="td2"><input type=text name="text1" value="haha"/></td>
<td  id="td3"><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
 <td><input type=text name="text1" value="haha"/></td>
</tr>
<tr>
 <td><input type=text name="text1" value=""/>    </td>
 <td><input type=text name="text1" value=""/>   </td>
 <td> <input type=text name="text1" value=""/>   </td>
</tr>
<tr>
 <td><input type=text name="text1" value=""/>    </td>
 <td><input type=text name="text1" value=""/>   </td>
 <td> <input type=text name="text1" value=""/>   </td>
</tr>
</table>
</p>
</body>
</html>

原创粉丝点击