请教如何让两个图层鼠标拖动互换

Jomwave 2007-02-27 03:45:30
如何让两个或多个图层只能左右互换位置,而不能在原由图层上或下插入,互换位置后并能够保存当前位置.
...全文
275 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jomwave 2007-02-27
  • 打赏
  • 举报
回复
解决了我在给30分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jomwave 2007-02-27
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title>
<style>
.removableObj
{
height:25;position:relative;
}
</style>
<script language="javascript">
var beginMoving=false;
var sourceObj=null;
var objectObj=null;
var objectObj2=null;
function MouseDownToMove(obj){
obj.style.zIndex=1;
obj.mouseDownY=event.clientY;
obj.mouseDownX=event.clientX;
beginMoving=true;
obj.setCapture();
sourceObj=obj;
objectObj=null;
}

function MouseMoveToMove(obj){
if(!beginMoving) return false;
obj.style.top = (event.clientY-obj.mouseDownY);
obj.style.left = (event.clientX-obj.mouseDownX);
}
function MouseUpToMove(obj){
if(!beginMoving) return false;
obj.releaseCapture();
obj.style.top=0;
obj.style.left=0;
obj.style.zIndex=0;
beginMoving=false;
window.setTimeout("swapFun()",20);
}

function MouseOverFun(obj)
{
if(obj==sourceObj) return false;
objectObj=obj;
}

function MouseOverFun2(obj)
{
objectObj2=obj;
}

function swapFun()
{
if(sourceObj!=null && objectObj!=null) objectObj.insertAdjacentElement("beforeBegin",sourceObj);
else if(sourceObj!=null && objectObj2!=null) objectObj2.insertAdjacentElement("beforeEnd",sourceObj);
sourceObj=null;
objectObj=null;
objectObj2=null;
}
</script>
</head>

<body>

<table border="1" width="100%" height="25">
<tr>
<td width="34%" valign="top" height="25" onmouseover="MouseOverFun2(this);" >
<table border="1" width="100%" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
<tr>
<td width="23%">1</td>
<td width="21%">2</td>
</tr>
<tr>
<td width="23%"> </td>
<td width="21%"> </td>
</tr>
</table>
</td>
<td width="32%" valign="top" height="25" onmouseover="MouseOverFun2(this);" >
<table border="1" width="100%" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
<tr>
<td width="21%" height="17">3</td>
</tr>
<tr>
<td width="21%">4</td>
</tr>
</table>
</td>
<td width="34%" valign="top" height="25" onmouseover="MouseOverFun2(this);" >
<table border="1" width="100%" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
<tr>
<td width="100%">5</td>

</tr>
<tr>
<td width="100%"></td>

</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
这是我从网上当的代码,但这个只能插入而不能互换位置
cuigod 2007-02-27
  • 打赏
  • 举报
回复
这个需求不是30分的需求……楼下的来解答……

87,991

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧