我在具有众多功能的各种文件中制作了很多“js-classes” - 该项目太大了,无法发布代码。
不知何故,我直接在终点线上创建了一个bug。在某些浏览器(例如ff)中的含义它不执行所需的功能(它在较早的阶段正确执行,而不更改执行该功能的代码,同时不更改函数的代码)。
我用这个方案创建了js-classes和underlaying函数:
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未定义 - 似乎有一个关闭括号丢失 - 我现在正在搜索,它不在gameEngine中,这意味着它是上面的一个类
最后一个错误是评论我意外没有通过“//”注释掉 - onclick解决了问题
非常感谢伟大和快速的高级支持! 现在我可以在摆脱刚刚发现的性能问题后准备好上传所有内容。 再次非常感谢你真的帮了我很多!!
答案 0 :(得分:3)
而不是使用hrefs,你应该点击链接:
<a onclick="GLOBAL_gameEngine.restartLevel1()">Try Again</a>
另外,如果你想使用href,你仍然需要将你的href用引号括起来
<a href="javascript:GLOBAL_gameEngine.restartLevel1()">Try Again</a>