我需要关于Javascript基础的帮助,我的问题是我的开始按钮,当它点击它时,应该创建一个提示,要求用户输入名字,并将其存储在您创建的变量中。我的文档就绪功能工作正常,但是按钮不能正常工作。
这是我的代码,谢谢你帮我
<!-- Name: <Put name here> Date: <Put date here> Class: CSCI2447, Javascript Fundamentals Project X \-->
<!DOCTYPE html>
<html>
<head>
<title>POP-The- Bubble (CSCI2447)</title>
<!-- CSS styles: This is for me to worry about; not you. -->
<link href="css/game.css" rel="stylesheet" />
<link href="[https://fonts.googleapis.com/css2?family=Sunshiney&display=swap](https://fonts.googleapis.com/css2?family=Sunshiney&display=swap)" rel="stylesheet">
<script src = "jquery-3.5.1.min.js"> </script>
<script> $( document ).ready(function() { var first Name = prompt("Enter First Name of Gamer:"); </script>
</head>
<body>
<div id="content">
<h1>Pop-The-Bubble</h1>
<p>After clicking "start", you will have 30 seconds to click
on as many bubbles as you can. The bubbles will appear quickley so be ready!
</p>
<div id="controls">
<span id="score">0 pts</span>
<button type="button" id="start\_button">Start!</button>
</div>
<div id="gamespace">
<img class="gameimage" src="img/bubblefun2.png" height = "120" width = "120"
</div>
</body>
</html>
发布于 2020-10-02 12:54:46
您的函数应该用右花括号}和括号) => })结束
$( document ).ready(function() { var firstName = prompt("Enter First Name of Gamer:") });
在名字和名字之间还有一个空格,这会在javascript Unexpected identifier中抛出一个错误。删除空格,使其成为变量名firstName的一个字符串
https://stackoverflow.com/questions/64166136
复制相似问题