0

我在具有众多功能的各种文件中制作了很多“js-classes” - 该项目太大而无法发布代码。

不知何故,我直接在终点线创建了一个错误。这意味着在某些浏览器(例如 ff)中,它不执行所需的功能(它在早期阶段正确地执行了该功能,而无需更改执行该功能的代码,同时也没有更改该功能的代码)。

我用这个方案创建了 js-classes 和底层函数:

function ClassName(){
   this.FunctionName = function(){
   //something
   }
}

我在地址栏中得到的是: javascript:ClassName.FunctionName() 应该发生的是浏览器只是像 chrome 一样执行函数,例如,没有任何问题。

所以我猜测代码中的某个地方只有一个我找不到的坏字符(它不属于那里)或者在其他地方缺少“”(可能也在另一个类中) - 或类似的东西 - 这让一些浏览器解释它正确(例如,windows下的chrome和mac下的safari但不是windows下的),而其他浏览器则没有。

但我希望从 Stack Overflow 的一位专业人士那里得到一些线索,告诉我地址​​栏的这种行为可能是什么原因,或者如何找到那些丢失的字符或那些根本不属于代码的字符. 什么是最佳实践,可能有任何工具吗?

chrome和ie开发工具(f12)和firefox firebug没有给我任何控制台错误,所以我现在真的一无所知,也许它在html中?我可以发布 html,因为它不是很大,因为大部分内容都是由 js 创建的。

<!DOCTYPE HTML>

<html>

<head>
    <title>
        engine demo build
    </title>

    <style type="text/css" title="currentStyle" media="screen">
        @import "style_l.css";
    </style>

    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <meta name="Content-Language" content="en-us">
    <meta name="Language" content="english, en-us">

    <script type="text/javascript" src="Engine.KeyboardDefines.js"></script>
    <script type="text/javascript" src="Engine.HelpFunctions.js"></script>
    <script type="text/javascript" src="Engine.BagaObject.js"></script>
    <script type="text/javascript" src="Engine.CollisionRect.js"></script>
    <script type="text/javascript" src="Engine.ImageObject.js"></script>
    <script type="text/javascript" src="Engine.ParallaxLayer.js"></script>
    <script type="text/javascript" src="Autoscroller.LevelObject.js"></script>
    <script type="text/javascript" src="Engine.SpriteImageObject.js"></script>
    <script type="text/javascript" src="Autoscroller.Player.js"></script>
    <script type="text/javascript" src="JumpAndRun.Player.js"></script>
    <script type="text/javascript" src="Adventure.Player.js"></script>
    <script type="text/javascript" src="JumpAndRun.Gate.js"></script>
    <script type="text/javascript" src="JumpAndRun.Switch.js"></script>
    <script type="text/javascript" src="JumpAndRun.Box.js"></script>
    <script type="text/javascript" src="JumpAndRun.Dragon.js"></script>
    <script type="text/javascript" src="JumpAndRun.Crane.js"></script>
    <script type="text/javascript" src="JumpAndRun.Golem.js"></script>
    <script type="text/javascript" src="Autoscroller.Obstacles.js"></script>
    <script type="text/javascript" src="Autoscroller.ObstaclesGround.js"></script>
    <script type="text/javascript" src="Adventure.ObstaclesGround.js"></script>
    <script type="text/javascript" src="Adventure.ObstaclesGroundCastle.js"></script>
    <script type="text/javascript" src="Adventure.ConversationIndicator.js"></script>
    <script type="text/javascript" src="Autoscroller.ObstaclesCeiling.js"></script>
    <script type="text/javascript" src="JumpAndRun.Obstacles.js"></script>
    <script type="text/javascript" src="JumpAndRun.ObstaclesGround.js"></script>
    <script type="text/javascript" src="JumpAndRun.ObstaclesGolemGround.js"></script>
    <script type="text/javascript" src="JumpAndRun.ObstaclesSpikes.js"></script>
    <script type="text/javascript" src="JumpAndRun.ObstaclesGroundLow.js"></script>
    <script type="text/javascript" src="JumpAndRun.ObstaclesGoals.js"></script>
    <script type="text/javascript" src="Autoscroller.GoalObject.js"></script>
    <script type="text/javascript" src="GameEngine.js"></script>
    <script type="text/javascript" src="Engine.EngineCore.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <script type="text/javascript" src="Engine.FPSObject.js"></script>

</head>

<body>
    <div class='GAMEmt-std'></div>

    <div id='debug'></div>

    <div id='GAMEglobalwrapper'>
        <div id='sounds'>
            <div id='bgmusic'>
                <audio id='l1bg' loop>
                    <source src='assets/audio/musicTracks/Longing_for_Tumbleweeds_by_Admiral_Bob_feat_Snowflake.mp3' type='audio/mp3'/>
                    <source src='assets/audio/musicTracks/Longing_for_Tumbleweeds_by_Admiral_Bob_feat_Snowflake.ogg' type='audio/ogg'/>

                    <p>seeing this message can have 2 possible causes:
                    <br>
                    1. You are using a browser which is not supported or
                    <br>
                    2. You are using Safari on windows (or linux? - not tested till now)
                    <br><br>
                    Solution:
                    <br>
                    In the first case get a supported browser
                    <br>
                    In the second case download Apple Quicktime, close Safari, install Quicktime, run Quicktime till advertisement appears, close Quicktime, run Safari again, browse to this site.
                </audio><!--l1bg-->

                <audio id='l2bg' loop>
                    <source src='assets/audio/musicTracks/Two_Swords_by__ghost.mp3' type='audio/mp3'/>
                    <source src='assets/audio/musicTracks/Two_Swords_by__ghost.ogg' type='audio/ogg'/>
                </audio><!--l2bg-->

                <audio id='l3bg' loop>
                    <source src='assets/audio/musicTracks/Real_good_day_by_calling_sister_midnight.mp3' type='audio/mp3'/>
                    <source src='assets/audio/musicTracks/Real_good_day_by_calling_sister_midnight.ogg' type='audio/ogg'/>
                </audio><!--l2bg-->

                <audio id='l4bg' loop>
                    <source src='assets/audio/musicTracks/Dance_of_Light_Pixies_by_onlymeith.mp3' type='audio/mp3'/>
                    <source src='assets/audio/musicTracks/Dance_of_Light_Pixies_by_onlymeith.ogg' type='audio/ogg'/>
                </audio><!--l4bg-->

                <audio id='scenebg' loop>
                    <source src='assets/audio/musicTracks/Longing_spacious_choir_remix_by_zep_hurme.mp3' type='audio/mp3'/>
                    <source src='assets/audio/musicTracks/Longing_spacious_choir_remix_by_zep_hurme.ogg' type='audio/ogg'/>
                </audio><!--l2bg-->
            </div><!--bgmusic-->

            <div id='soundfx'>
                <audio id='hitsound'>
                    <source src='assets/audio/soundFX/standardHit.mp3' type='audio/mp3'/>
                    <source src='assets/audio/soundFX/standardHit.ogg' type='audio/ogg'/>
                </audio><!--hitsound-->

                <audio id='switchsound'>
                    <source src='assets/audio/soundFX/switch.mp3' type='audio/mp3'/>
                    <source src='assets/audio/soundFX/switch.ogg' type='audio/ogg'/>
                </audio><!--switchsound-->

                <audio id='gatesound'>
                    <source src='assets/audio/soundFX/gate.mp3' type='audio/mp3'/>
                    <source src='assets/audio/soundFX/gate.ogg' type='audio/ogg'/>
                </audio><!--gatesound-->

                <audio id='boxsound'>
                    <source src='assets/audio/soundFX/box.mp3' type='audio/mp3'/>
                    <source src='assets/audio/soundFX/box.ogg' type='audio/ogg'/>
                </audio><!--boxsound-->
            </div><!--soundfx-->
        </div><!--sounds-->

        <canvas id="canvas" ondrop="GLOBAL_gameEngine.drop(event)" ondragover="GLOBAL_gameEngine.allowDrop(event)" width="800" height="450"> 
            <p>You will need a current version of a major browser to play this game</p>
        </canvas>

        <div id='gameoverscreen'>
            <div id='gameover'></div>

            <div id='lvl1gameover'>
                <a href=javascript:GLOBAL_gameEngine.restartLevel1()>Try Again</a>
            </div><!--lvl1gameover-->

            <div id='lvl2gameover'>
                <a href=javascript:GLOBAL_gameEngine.resetAtCheckpoint()>Reset At Last Checkpoint</a>
            </div><!--lvl2gameover-->

            <div id='lvl4gameover'>
                <a href=javascript:GLOBAL_gameEngine.restartLevel4()>Somenone saw you. Try again. -></a>
            </div><!--lvl4gameover-->
        </div><!--gameover-->

        <div id='storyscreen'>
            <div id='languagepicker'>
                <!--a href=javascript:GLOBAL_gameEngine.setLanguage('en')-->English (soon)<!--/a-->
                <br><br>
                <a href=javascript:GLOBAL_gameEngine.setLanguage('de')>Deutsch</a>
            </div><!--languagepicker-->

            <div id='sequenz1'>
                <div id='sequenz1question'>
                </div><!--sequenz1question-->

                <div id='sequenz1img'>
                </div><!--sequenz1img-->

                <div id='sequenz1txt'>
                </div><!--sequenz1txt-->
            </div><!--sequenz1-->

            <div id='sequenz2'>
                <div id='sequenz2question'>
                </div><!--sequenz2question-->

                <div id='sequenz2img'>
                </div><!--sequenz2img-->

                <div id='sequenz2txt'>
                </div><!--sequenz2txt-->
            </div><!--sequenz2-->

            <div id='sequenz3'>
                <div id='sequenz3question'>
                </div><!--sequenz3question-->

                <div id='sequenz3img'>
                </div><!--sequenz3img-->

                <div id='sequenz3txt'>
                </div><!--sequenz3txt-->
            </div><!--sequenz3-->

            <div id='sequenz4'>
                <div id='sequenz4question'>
                </div><!--sequenz4question-->

                <div id='sequenz4img'>
                </div><!--sequenz4img-->

                <div id='sequenz4txt'>
                </div><!--sequenz4txt-->
            </div><!--sequenz4-->

            <div id='sequenz5'>
                <div id='sequenz5question'>
                </div><!--sequenz5question-->

                <div id='sequenz5img'>
                </div><!--sequenz5img-->

                <div id='sequenz5txt'>
                </div><!--sequenz5txt-->
            </div><!--sequenz5-->

            <div id='conversation' ondrop="GLOBAL_gameEngine.drop(event)" ondragover="GLOBAL_gameEngine.allowDrop(event)">
                <div id='conversationplayertxt'>
                </div><!--conversationplayertxt-->

                <div id='conversationvillagertxt'>
                </div><!--conversationvilagertxt-->

                <div id='conversationdirection'>
                </div><!--conversationdirection-->

                <div id='conversationimg'>
                </div><!--conversationImage-->
            </div><!--conversation-->
        </div><!--storyscreen-->

        <div id='hint' draggable='false'>
        </div><!--hint-->

        <div id='gui'>
            <div id='healthmeter'>
                <div id='hp1'><img src='assets/visuals/images/heart.png'></div>
                <div id='hp2'><img src='assets/visuals/images/heart.png'></div>
                <div id='hp3'><img src='assets/visuals/images/heart.png'></div>
                <div class='clearleft'></div>
            </div>

            <div id='itembackpack'>
                <div id='pickaxe' alt='pickaxe' title='pickaxe' class='firstitem'><img src='assets/visuals/images/pickaxe.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "pickaxe")'></div>
                <div id='letter' alt='letter' title='letter' class='notfirstitem'><img src='assets/visuals/images/letter.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "letter")'></div>
                <div id='iron' alt='iron' title='iron' class='notfirstitem'><img src='assets/visuals/images/iron.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "iron")'></div>
                <div id='nails' alt='nails' title='nails' class='notfirstitem'><img src='assets/visuals/images/nails.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "nails")'></div>
                <div id='dagger' alt='dagger' title='dagger' class='notfirstitem'><img src='assets/visuals/images/dagger.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "dagger")'></div>
                <div id='book' alt='book' title='book' class='notfirstitem'><img src='assets/visuals/images/book.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "book")'></div>
                <div id='amulet' alt='amulet' title='amulet' class='notfirstitem'><img src='assets/visuals/images/amulet.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "amulet")'></div>
                <div id='ring' alt='ring' title='ring' class='notfirstitem'><img src='assets/visuals/images/ring.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "ring")'></div>
                <div id='mouse' alt='mouse' title='mouse' class='notfirstitem'><img src='assets/visuals/images/mouse.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "mouse")'></div>
                <div id='wasps' alt='wasps' title='wasps' class='notfirstitem'><img src='assets/visuals/images/wasps.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "wasps")'></div>
                <div id='dog' alt='dog' title='dog' class='notfirstitem'><img src='assets/visuals/images/dog.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "dog")'></div>
                <div id='sleepingpowder' alt='sleepingpowder' title='sleepingpowder' class='notfirstitem'><img src='assets/visuals/images/sleepingpowder.jpg' draggable='true' ondragstart='javascript:GLOBAL_gameEngine.drag(event, "sleepingpowder")'></div>
            </div>
        </div><!--gui-->
    </div>

    <script>
        var debug = document.getElementById('debug');

        debug.log = function(){
            this.innerHTML = "";
            for(var i = 0; i < arguments.length; i++)
            {
                this.innerHTML += arguments[i] + " ";
            }
        }
    </script>
</body>

</html>

忘了提:页面显示[object Object]

将其更改为 onclick,现在我得到: ReferenceError: GameEngine is not defined - 似乎缺少一个右括号 - 我现在正在搜索,它不在 gameEngine 中,这意味着它是上面的类之一

最后一个错误是我不小心没有通过“//”注释掉的评论 - onclick 解决了问题

非常感谢您的大力支持!现在我可以在摆脱刚刚发现的性能问题后准备上传所有内容。再次非常感谢你真的帮了我很多!

4

1 回答 1

3

而不是使用hrefs,你应该让你的链接点击:

<a onclick="GLOBAL_gameEngine.restartLevel1()">Try Again</a>

此外,如果您想使用 href,您仍然需要将您的 href 括在引号中

<a href="javascript:GLOBAL_gameEngine.restartLevel1()">Try Again</a>
于 2012-12-19T19:15:41.647 回答