这段代码中哪里错了,怎么有时候报错,有时候能正常运行呢?
刘津宇教编程 企业官方账号 2009-06-07 07:41:14 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>层移动并且保存坐标的例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="Design Corp" content="myhhe.cn" />
<meta name="Designer" content="hayden" />
<meta name="Designer mail" content="hayden@yeah.net" />
<meta name="robots" content="hayden" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script src="jquery-1.2.6.js" type="text/javascript"/>
<script language="JavaScript" type="text/javascript">
var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var oevent=new Function('e','if (!e) e = window.event;return e')
//层移动
function Move_obj(obj){
var x,y;
D(obj).onmousedown=function(e){
drag_=true;
with(this){
style.position="absolute";var temp1=offsetLeft;var temp2=offsetTop;
x=oevent(e).clientX;y=oevent(e).clientY;
document.onmousemove=function(e){
if(!drag_)return false;
with(this){
style.left=temp1+oevent(e).clientX-x+"px";
style.top=temp2+oevent(e).clientY-y+"px";
}
}
}
document.onmouseup=new Function("drag_=false");
}
}
//将层的坐标发送到服务端,并且保存下来
function saveLayerCoordinate(obj)
{
var currentLayer_left,currentLayer_top;
currentLayer_left=D(obj).style.left+"px";
currentLayer_top=D(obj).style.top+"px";
$.post(
'http://localhost:41704/Work.asmx/UpdateCoordinate',
{'currentLayer_left':currentLayer_left,'currentLayer_top':currentLayer_top},
function(data){
//var coordinate = eval("("+data+")");
alert(data.text);
//window.open("Move.htm?currentLayer_left="+coordinate[0].currentLayer_left+"&OnlyMusicName="+coordinate[0].currentLayer_top,"newwindow","height=100,width=200,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
}
);
}
</script>
</head>
<body onload="">
<div id="test" style="background-color:#0099CC;width:200px;height:100px;border:1px #000 solid;" onmouseover='Move_obj("test")'>
点击拖动层
</div>
<div id="save" style="width:200px;height:40px;border:1px #000 solid;" onclick='saveLayerCoordinate("test")' >
保存坐标
</div>
</body>
</html>