var rDrag = {
o: null,
init: function (o) {
o.onmousedown = this.start;
},
start: function (e) {
var o;
e = rDrag.fixEvent(e);
e.preventDefault && e.preventDefault();
rDrag.o = o = this;
o.x = e.clientX - rDrag.o.offsetLeft;
o.y = e.clientY - rDrag.o.offsetTop;
document.onmousemove = rDrag.move;
document.onmouseup = rDrag.end;
},
move: function (e) {
e = rDrag.fixEvent(e);
var oLeft, oTop;
oLeft = e.clientX - rDrag.o.x;
oTop = e.clientY - rDrag.o.y;
rDrag.o.style.left = oLeft + 'px';
rDrag.o.style.top = oTop + 'px';
},
end: function (e) {
e = rDrag.fixEvent(e);
rDrag.o = document.onmousemove = document.onmouseup = null;
},
fixEvent: function (e) {
if (!e) {
e = window.event;
e.target = e.srcElement;
e.layerX = e.offsetX;
e.layerY = e.offsetY;
}
return e;
}
}
window.onload = function () {
var obj = document.getElementById('divUpdate');
rDrag.init(obj);
}
html代码:
<form id="form1" runat="server">
<div id="divUpdate" style="display: none; width: 300px; float: right;" class="white_content">
<div class="tc_content">
<div class="tc_info">
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F1F1F1">
<tr>
<td align="right" bgcolor="#F9F9F9">
传感器名称:
</td>
<td align="left" bgcolor="#F9F9F9">
<select id="EqpName" οnchange="showListSelfNum(document.getElementById('EqpName').value)">
<option></option>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="#F9F9F9">
传感器编号:
</td>
<td align="left" bgcolor="#F9F9F9">
<select id="EqpselfNum">
<option></option>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="#F9F9F9">
设备X位置:
</td>
<td align="left" bgcolor="#F9F9F9">
<input type="text" class="dj_input01" size="15" runat="server" id="uXlocation" />
</td>
</tr>
<tr>
<td align="right" bgcolor="#F9F9F9">
设备Y位置:
</td>
<td align="left" bgcolor="#F9F9F9">
<input type="text" class="dj_input01" size="15" runat="server" id="uYlocation" />
</td>
</tr>
<tr>
<td>
<input type="button" style="position: absolute; left: 70px;" id="btnUpSure" class="but01"
value="确定" />
</td>
<td>
<input type="button" style="position: absolute; left: 170px;" id="btnUpCancel" class="but01"
value="取消" />
</td>
</tr>
</table>
</div>
</div>
</div>
<form>