<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
function fun()
{
document.getElementById("yundong").style.marginTop+=50;
}
</script>
<body>
<p>
<img src="image/wb1.jpg" width="177" height="123" id="yundong" />
</p>
<p>&nbsp;</p>
<p>
  <input type="submit" name="button" id="button" value="提交" onclick="fun()" />
</p>
</body>
</html>单击按钮调用fun()函数怎么只能移动一下。就报错。  说参数值错误!

解决方案 »

  1.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript">
    function fun()
    {
        //document.getElementById("yundong").style.marginTop+=50;
        //alert(document.getElementById("yundong").style.top);
        var t=parseInt(document.getElementById("yundong").style.top);
        document.getElementById("yundong").style.top=t+50+"px";
    }
    </script>
    <body>
    <p>
    <img src="image/wb1.jpg" width="177" height="123" id="yundong" style="top:100px; position:absolute" />
    </p>
    <p>&nbsp;</p>
    <p>
      <input type="button" name="button" id="button" value="提交" onclick="fun()" />
    </p>
    </body>
    </html>