注册 登录
编程论坛 JavaScript论坛

图片随鼠标移动的代码哪里有问题,请指点一下,谢谢

zChicaca 发布于 2010-12-28 23:46, 809 次点击
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
    .div1{
        position:absolute;
        left:88px;
        top:88px;
    }
</style>
<script type="text/javascript" language="javascript">
    function move(x,y){
        obj=document.getElementById("mypic");
        obj.style.left=x;
        obj.style.top=y;
    }
</script>
</head>

<body  onMousemove="move(event.x,event.y)">
查看信息:
<div class="div1" id="mypic">
    <img  src="imgs/2004821135239435.gif"/>
</div>
</body>
</html>
10 回复
#2
zmh8862010-12-29 14:10
居然是这2行作怪?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
#3
zChicaca2010-12-29 19:17
啊,那两行去了就没问题吗?
#4
zChicaca2010-12-29 19:25
我试了下,那两行去了还真没问题,不过只有IE得行
#5
zChicaca2010-12-29 19:27
能不能说下那两行作怪的原因呢?
#6
aspic2010-12-30 10:03
明明就是自己的代码不标准。。。怪人家那两行做什么
#7
zChicaca2010-12-30 10:37
怎么不标准了啊,那不是自动生成的吗
#8
aspic2010-12-30 15:06
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
    .div1{
        position:absolute;
        left:88px;
        top:88px;
    }
</style>
</head>

<body>
查看信息:
<div class="div1" id="mypic">
    <img  src="imgs/2004821135239435.gif"/>
</div>
<script type="text/javascript">
document.onmousemove = function(){
    obj=document.getElementById("mypic");
    obj.style.left=event.clientX + 'px';
    obj.style.top=event.clientY + 'px';
}
</script>
</body>
</html>
根本就不是那两行的问题好不
没有那两行肯定不是标准的xhtml文档了啊........
#9
aspic2010-12-30 15:12
程序代码:
document.onmousemove = function(evt){
    obj=document.getElementById("mypic");
    obj.style.left=(window.event || evt).clientX + 'px';
    obj.style.top=(window.event || evt).clientY + 'px';
}
修改一下 兼容FF
#10
zmh8862010-12-30 15:25
以下是引用aspic在2010-12-30 10:03:36的发言:

明明就是自己的代码不标准。。。怪人家那两行做什么
菜鸟我从不考虑兼容问题 所以只能怪那2行。
#11
baoyuwang1982011-01-22 19:42
那是W3C标准,去了 搜索引擎根本找不到你,还是找找其他原因.
1