那位高手看看这段代码,为啥单击一次向右移动按钮移动一次,再单击图片就不移动了?我是用的IE浏览器,每个版本我都测试了结果还是那样,估计不是浏览器版本的事,是不是算法出现问题,我觉得要的是算法出现问题不可能移动。附加:Css部分我没加。
<!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>supermali</title>
<link href="file:///E:\C#练习\supermali\supermali\supermali.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script language ="javascript" >
function malis()
{ this .x=0;
this.y=0;
this.show =function()
{
var picture=document.getElementById ("picture");
var lefts=picture.style.width ;
lefts=parseInt (lefts .substr(0,lefts .length-2));
picture .style.left=(lefts +100)+"px";
}
}
var qq=new malis ();
</script>
<table class ="table1" border :1px>
<tr align=center ><td colspan =3>游戏控制中心</td></tr>
<tr><td>**</td><td><input type="button" value ="向上移动"/></td><td>**</td></tr>
<tr><td>**</td><td></td><td><input type="button" value ="向右移动" onclick ="qq.show()" /></td></tr>
</table>
<div class ="div1">
<img class ="img1"src ="image/122.gif" id ="picture" style ="top :50px;left :80px; width :50px;height :40px;position :absolute ;"/>
</div>
</body>
</html>
<!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>supermali</title>
<link href="file:///E:\C#练习\supermali\supermali\supermali.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script language ="javascript" >
function malis()
{ this .x=0;
this.y=0;
this.show =function()
{
var picture=document.getElementById ("picture");
var lefts=picture.style.width ;
lefts=parseInt (lefts .substr(0,lefts .length-2));
picture .style.left=(lefts +100)+"px";
}
}
var qq=new malis ();
</script>
<table class ="table1" border :1px>
<tr align=center ><td colspan =3>游戏控制中心</td></tr>
<tr><td>**</td><td><input type="button" value ="向上移动"/></td><td>**</td></tr>
<tr><td>**</td><td></td><td><input type="button" value ="向右移动" onclick ="qq.show()" /></td></tr>
</table>
<div class ="div1">
<img class ="img1"src ="image/122.gif" id ="picture" style ="top :50px;left :80px; width :50px;height :40px;position :absolute ;"/>
</div>
</body>
</html>
{
var picture=document.getElementById ("picture");
var lefts=picture.style.width ;
lefts=parseInt (lefts .substr(0,lefts .length-2));
picture .style.left=(lefts +100)+"px";
}
这是方法啊
改成 var lefts=picture.style.left;<!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>supermali</title>
<link href="file:///E:\C#练习\supermali\supermali\supermali.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script language ="javascript" >
function malis()
{ this .x=0;
this.y=0;
this.show =function()
{
var picture=document.getElementById("picture");
var lefts=picture.style.left;
//alert(lefts);
lefts=parseInt (lefts .substr(0,lefts .length-2));
picture .style.left=(lefts +100)+"px";
}
}
var qq=new malis ();
</script>
<table class ="table1" border :1px>
<tr align=center ><td colspan =3>游戏控制中心</td></tr>
<tr><td>**</td><td><input type="button" value ="向上移动"/></td><td>**</td></tr>
<tr><td>**</td><td></td><td><input type="button" value ="向右移动" onclick ="qq.show()" /></td></tr>
</table>
<div class ="div1">
<img class ="img1"src ="image/122.gif" id ="picture" style ="top :50px;left :80px; width :50px;height :40px;position :absolute ;"/>
</div>
</body>
</html>