当前位置: 代码迷 >> Java Web开发 >> JavaScript。偏题,人在线
  详细解决方案

JavaScript。偏题,人在线

热度:22   发布时间:2016-04-17 01:20:33.0
JavaScript。。难题,人在线
HTML code
<table width="157" height="141" border="1">  <tr>    <td bgcolor="#FFFFFF"><div align="center">A</div></td>    <td bgcolor="#FFFFFF"><div align="center">B</div></td>  </tr>  <tr>    <td><div align="center">D</div></td>    <td><div align="center">E</div></td>  </tr></table>


单鼠标点击图片A的时候并移动到图片E处,然后松开鼠标,要使此时A与E的位置调换。同理其他图片也可以这样互相移动。。。

------解决方案--------------------
<head>
<script type = "text/javascript">

var pointFirst;
var pointSecond;

var first;
var second

function onClick(id){  
first = id;
pointFirst = document.getElementById(id).innerText;
}

function onMouseUp(id){
second = id;
pointSecond = document.getElementById(id).innerText;
tempImageChange();
}

function tempImageChange(){  
document.getElementById(first).innerText = pointSecond;
document.getElementById(second).innerText = pointFirst;
}

</script>
</head>

<table width="157" height="141" border="1">
<tr>
<td id="aId" bgcolor="#FFFFFF" onmousedown ="onClick('aId')" onmouseup="onMouseUp('aId')" value="a"><div align="center">A</div></td>
<td id="bId" bgcolor="#FFFFFF" onmousedown ="onClick('bId')" onmouseup="onMouseUp('bId')"><div align="center">B</div></td>
</tr>
<tr>
<td id = "dId" onmousedown ="onClick('dId')" onmouseup="onMouseUp('dId')"><div align="center">D</div></td>
<td id = "eId" onmousedown ="onClick('eId')" onmouseup="onMouseUp('eId')"><div align="center">E</div></td>
</tr>
</table>

上面的原理差不多!
  相关解决方案