gpt4 book ai didi

javascript 不执行而是在地址栏中显示函数名称

转载 作者:行者123 更新时间:2023-11-28 20:43:15 24 4
gpt4 key购买 nike

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

不知怎的,我直接在终点线制造了一个错误。这意味着在某些浏览器(例如 ff)中,它不会执行所需的函数(它在早期阶段正确执行该函数,而无需更改执行该函数背后的代码,也无需同时更改该函数的代码)。

我使用此方案创建了 js 类和底层函数:

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 解决了问题

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

最佳答案

您应该在点击上创建链接,而不是使用 href:

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

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

<a href="javascript:GLOBAL_gameEngine.restartLevel1()">Try Again</a>

关于javascript 不执行而是在地址栏中显示函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com