简体   繁体   English

HTML onfocus 不调用 Javascript 函数

[英]HTML onfocus not calling Javascript function

So I'm making a kind of like a telltale game using readonly inputs.所以我正在制作一种类似使用只读输入的告密游戏。 I'm using onfocus to call a javascript function, but it won't run the function.我正在使用 onfocus 调用 javascript 函数,但它不会运行该函数。 I'm new to stackoverflow so if you can't see my code, please tell me.我是 stackoverflow 的新手,所以如果您看不到我的代码,请告诉我。 Also, I'm coding on Chromebook so the links to the CSS file and JS file are drive links.另外,我在 Chromebook 上编码,因此 CSS 文件和 JS 文件的链接是驱动器链接。

EDIT: I think this is a problem on my computer's end since it's working perfectly fine when I run it on here.编辑:我认为这是我电脑端的一个问题,因为当我在这里运行它时它工作得很好。

EDIT 2: MY GOD I'M AN IDIOT!编辑 2:天哪,我是个白痴! I misspelled something in the javascript section, something that DIDN'T EVEN MATTER TO MY GAME was MISSPELLED.我在 javascript 部分拼错了一些东西,甚至对我的游戏都不重要的东西拼错了。

 var meep = 0; function changeText() { document.getElementById("startInput").blur(); if (meep === 0) { document.getElementById("startInput").value = "'Why are you here?'"; } else if (meep === 1) { document.getElementById("startInput").value = "'I'm not who I used to be...'"; } else if (meep === 2) { document.getElementById("startInput").value = "'I'm looking for Malya,' you say."; } else if (meep === 3) { document.getElementById("startInput").value = "'I assume that is you.'"; } else if (meep === 4) { document.getElementById("startInput").value = "..."; } meep++; }
 <link rel="stylesheet" href="file:///media/fuse/drivefs-ba3df23145370ebbe0addbed7174e8b0/root/html/New%20Website/style.css"> <script src="file:///media/fuse/drivefs-ba3df23145370ebbe0addbed7174e8b0/root/html/New%20Website/code.js"></script> <body> <input type="text" class="no-outline" value="'Who are you?'" id="startInput" onfocus="changeText()" readonly> <input type="text" class="tutorial" id="tutorial" placeholder="Click on text to change it." readonly>

This works just fine.这工作得很好。 If it doesn't work on your machine, please check out the console do you have any errors, because the line如果它在您的机器上不起作用,请检查控制台您是否有任何错误,因为该行

<script src="file:///media/fuse/drivefs-ba3df23145370ebbe0addbed7174e8b0/root/html/New%20Website/code.js"></script>

could create problems if the script doesn't work right.如果脚本不能正常工作,可能会产生问题。

Yeah, something that didn't matter to my game, I took out of the code for stackoverflow and OF COURSE it was misspelled.是的,一些对我的游戏无关紧要的东西,我删除了 stackoverflow 的代码,当然它拼写错误了。 So the solution, when making a random variable you don't even need, do NOT spell document as doument.因此,解决方案是,在创建您甚至不需要的随机变量时,不要将文档拼写为 doument。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM