baidu_32147215 2015-10-19 14:52 采纳率: 0%
浏览 1734

一个JS小程序出现了超级奇怪的bug,实在找不到问题求大神支招


 <!DOCTYPE html>
<html>
<head>
    <title>Hello World</title>
    <link rel="stylesheet" type="text/css" href="Marion.css">
    <script language="javascript" type="text/javascript">
        function marion () {
            this.x=0;
            this.y=0;
            this.move=function(direct){
                var myimg=document.getElementById("img12");
                var left=myimg.style.left;
                left=left.substr(0,(left.length-2));
                var top=myimg.style.top;
                top=top.substr(0,(top.length-2));
                switch(direct){
                    case '0':window.alert(myimg.style.left+"+"+myimg.style.top);
                    myimg.style.top=(top-40)+"px";break;
                    case '1':myimg.style.left=(left-40)+"px";break;
                    case '2':myimg.style.top=(top+40)+"px";break;
                    case '3':myimg.style.left=(left+40)+"px";break;

                }
            }
        }
        var mario=new marion();
        function marionmove(direct){
            mario.move(direct);
        }
    </script>
</head>
<body>
<div class="Marion">
    <img id="img12" src="aa.jpg"  class="img1"/>
</div>
<table border="1" style="margin: 0 0 0 500px">
    <tr><td colspan="3" align="center">游戏键盘</td></tr>
    <tr><td></td><td><input type="button" value="↑" onclick="marionmove('0')"/></td><td></td></tr>
    <tr><td><input type="button" value="←" onclick="marionmove('1')"/></td><td><input type="button" value="↓" onclick="marionmove('2')"/></td><td><input type="button" value="→" onclick="marionmove('3')" /></td></tr>
    </table>
</body>
</html>




  • 写回答

4条回答 默认 最新

  • baidu_32147215 2015-10-19 14:56
    关注

    <!DOCTYPE html>


    Hello World

    <br> function marion () {<br> this.x=0;<br> this.y=0;<br> this.move=function(direct){<br> var myimg=document.getElementById(&quot;img12&quot;);<br> var left=myimg.style.left;<br> left=left.substr(0,(left.length-2));<br> var top=myimg.style.top;<br> top=top.substr(0,(top.length-2));<br> switch(direct){<br> case &#39;0&#39;:window.alert(myimg.style.left+&quot;+&quot;+myimg.style.top);<br> myimg.style.top=(top-40)+&quot;px&quot;;break;<br> case &#39;1&#39;:myimg.style.left=(left-40)+&quot;px&quot;;break;<br> case &#39;2&#39;:myimg.style.top=(top+40)+&quot;px&quot;;break;<br> case &#39;3&#39;:myimg.style.left=(left+40)+&quot;px&quot;;break;</p> <pre><code> } } } var mario=new marion(); function marionmove(direct){ mario.move(direct); } &lt;/script&gt; </code></pre> <p></head><br> <body></p> <div class="Marion"> <img id="img12" src="aa.jpg" class="img1"/> </div> <table border="1" style="margin: 0 0 0 500px"> <tr><td colspan="3" align="center">游戏键盘</td></tr> <tr><td></td><td><input type="button" value="↑" onclick="marionmove('0')"/></td><td></td></tr> <tr><td><input type="button" value="←" onclick="marionmove('1')"/></td><td><input type="button" value="↓" onclick="marionmove('2')"/></td><td><input type="button" value="→" onclick="marionmove('3')" /></td></tr> </table> <p></body><br> </html><br> 上面的代码发瞎了。。</p>
    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题