<!-- 把下列代码加到<body>区域中 -->
<script language="JavaScript">
<!--
//该函数在调用过程中只需要在将要点击的单元格内的onclick事件中调用showme函数即可
//function showme(obj1, obj2)该函数主要为使点击的对象高亮度显示,并调用moveme函数,参数obj1为母体即<div>标签的id,obj2为点击对象本身
//function moveme(obj)该函数判断单元的移动,并调用相应的函数处理,obj参数为母体
//function moveup(obj,objtop)该函数使一个单元向上移动,参数obj为母体,objtop为母体的本身最高高度
//function movedown(obj,objbuttom)该函数使一个单元向下移动,参数obj为母体,objbuttom为母体的本身最低高度
var headHeight = 22;//每个标题的高度
var bodyHeight = 160;//母体高度
var objcount = 6;//项目的个数,要改变了项目的个数别忘了该这个东西
var step = 6;//移动速度(请确认可以被'bodyHeight-headHeight'整除,当前的设定可选速度为1,2,3,6,23,138)
var moving = false;//是否有移动的项目
function showme(obj1, obj2)
{
//以下循环为改变标题的背景颜色
if (moving)
return;
moving = true;
for(i=0;i<document.all.tags("td").length;i++)
if (document.all.tags("td")[i].className.indexOf('headtd') == 0)
document.all.tags("td")[i].className = 'headtd1';
obj2.className = 'headtd2';
moveme(obj1);
}
function moveme(obj)
{
idnumber = parseInt(obj.id.substr(4));
objtop = headHeight * (idnumber - 1);
objbuttom = bodyHeight + headHeight * (idnumber - 2);
currenttop = parseInt(obj.style.top);
if (currenttop >= objbuttom)
{
//检验出每一个应该向上移动的层
countid = 1;
for(i=0;i<document.all.tags("div").length;i++)
if (document.all.tags("div")[i].id == 'item'+countid+'body')
{
obj = document.all.tags("div")[i];
objtop = headHeight * (countid - 1);
if (countid == idnumber)
{
moveup(obj,objtop,false);
break;
}
else
moveup(obj,objtop,true);
countid++;
}
}
else if ((currenttop <= objtop) && (idnumber < objcount))
{
//检验出每一个应该向下移动的层
idnumber++;
countid = objcount;
for(i=document.all.tags("div").length-1;i>=0;i--)
if (document.all.tags("div")[i].id == 'item'+countid+'body')
{
obj = document.all.tags("div")[i];
objbuttom = bodyHeight + headHeight * (countid - 2);
if (countid == idnumber)
{
movedown(obj,objbuttom,false);
break;
}
else
movedown(obj,objbuttom,true);
countid--;
}
}
}
function moveup(obj,objtop,ismove)
{
currenttop = parseInt(obj.style.top);
if (currenttop > objtop)
{
obj.style.top = currenttop - step;
setTimeout('moveup('+obj.id+','+objtop+','+ismove+')',1)
return;
}<center>
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
//prnform.htext.value=prnhtml;
//prnform.submit();
//alert(prnhtml);
}
</script>
这些内容是不会被打印的<br>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<center>本部分以上不被打印</center>
<!--startprint-->
<table width="70%" align="center" bgcolor="#0000FF" cellpadding="2" cellspacing="1">
<tr bgcolor="#6699FF">
<td>
<div align="center">标题一</div>
</td>
<td>
<div align="center">标题二</div>
</td>
<td>
<div align="center">标题三</div>
</td>
<td>
<div align="center">标题四</div>
</td>
</tr>
<tr bgcolor="#6699FF">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<!--endprint-->
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
这些内容是不会被打印的
<div align="center">
<input type="button" name="print" value="预览并打印" onclick="preview()">
</div>
</center>