这段代码中哪里错了,怎么有时候报错,有时候能正常运行呢?

刘津宇教编程
企业官方账号
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>
...全文
66 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen_ya_ping 2009-06-08
  • 打赏
  • 举报
回复
那楼主你有时候出的是什么样的错误,讲一下,这样的话大家可以有针对的给你解决
  • 打赏
  • 举报
回复
调试JS代码
sijin 2009-06-08
  • 打赏
  • 举报
回复
可能是浏览器的关系
changjiangzhibin 2009-06-08
  • 打赏
  • 举报
回复
1) 看一下是否是浏览器兼容问题
2) 调试JS代码(使用工具,分浏览器看看)
Moon_F 2009-06-07
  • 打赏
  • 举报
回复
你要说下报什么错吧
xsm545 2009-06-07
  • 打赏
  • 举报
回复
帮顶
mengxj85 2009-06-07
  • 打赏
  • 举报
回复
如楼上所说,可能是JS错误,设置JS调试,出错时会提示JS错误
pengyong_tao 2009-06-07
  • 打赏
  • 举报
回复
很有可能是你的JS文件里面有错误。
我也有类似的情况。但大多数是JS或者CSS文件出错,。
wuyq11 2009-06-07
  • 打赏
  • 举报
回复
是否与浏览器兼容性相关

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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