简体   繁体   中英

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. I'm new to stackoverflow so if you can't see my code, please tell me. Also, I'm coding on Chromebook so the links to the CSS file and JS file are drive links.

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! I misspelled something in the javascript section, something that DIDN'T EVEN MATTER TO MY GAME was MISSPELLED.

 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. So the solution, when making a random variable you don't even need, do NOT spell document as doument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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