javascript - 无法获得警报或确认在 javascript 中工作
问题描述
编辑:感谢你们所有人,它已被修复(:非常感谢你们
我无法收到警报、确认或提示工作,这是我的代码(不是完整代码,但开头是我无法工作的部分,所以我离开了它并省略了代码的结尾,所以这里是:
var warGood = 0
var warEvil = 0
var life
var mh = false
var document.Gold = 1000;
var gems = 1000;
var lb = false
var Stellar_grenades = 0
var Cosmic_grenades = 0;
var Level = 1
var person
person = prompt("please enter your name", "Specimen")
if (person != null) {
if (person == "shit") {
alert("Really? choose a new MORE APPROPRIATE name", "Ok ill choose a new More APPROPRIATE name")
}
else if (person != "shit"){
if (person != null) {alert(
"welcome " + person + " to the universe")
}
}
alert(
"not too long ago your planet was blown up in the midst of a universal war, you luckily survived and fled to another planet");
alert("You are now here, On Planet Vecron, Here you will build up your base,")
alert("then you can eventually go on missions to distant planets,")
alert("Upon Reaching the final mission, you will notice one thing")
alert ("Your Not on a new planet, but rather a new universe,")
alert("this universe holds the Key to cosmic peace,")
alert(" This Key is the Community Pendant")
life = confirm("Do you have what it takes to get this pendant and end the universal war?")
if (life == true) {
alert("Thank you " + person + "You will make a fine adventurer");
alert("gold is the main currency Here on vecron")
alert(" If you want anything it can buy it, with a few exceptions")
alert("You cant buy the Community Pendant")
alert(" Or gems Or the special 12 summoners tools")
alert(" Shh the summoners tools will be talked about later")
alert("saving your game is important,")
alert("To Open the shop Press S")
alert("To Save Press F")
alert("To get money you simply have to press the money button!")
alert("The Ding Is to make sure you actually have good reflexes while in missions.")
alert("You get missions after you unlock the mission hall")
alert("then you can start the first journey on your many adventures")
document.write("you have " + document.Gold + " Gold and " + gems + " gems")
alert("Go Get that Pendant and save the world")
<img src = "logo.png" alt = "logo">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
我真的想不通,几周前它工作得很好,然后我休息了一会儿,然后又回来了,突然它就不再工作了
解决方案
Document.gold 不是有效的 JS。如果你想要全局变量,你可以使用var
关键字。这会将它们添加到全局范围。像这样:
var gold = 1000;
DOM
记录API的主要对象。HTML 文档被解析并以 JS 表示形式加载到内存中。然后,您可以修改将导致 UI 更新的 DOM。您已经在以下代码中执行此操作(稍作更改):
var gold = 1000;
var gems = 25;
document.write("you have " + gold + " Gold and " + gems + " gems")
推荐阅读
- ios - 设置接收通知的延迟并快速加载应用程序
- data-structures - 展开树中范围总和的伪代码?
- regex - 未捕获的 SyntaxError:无效的正则表达式:/^(?:[\d]+|me$/: 未终止的组
- javascript - 刷新页面后div总是上移
- styled-components - 黑暗主题如何通过样式化组件传递功能
- javascript - 如何将背景图像(在样式中设置)替换为 div 中的任何图像?
- ios - 找不到目标“x86_64-apple-ios-simulator”的模块“FBSDKCoreKit”;找到:arm64,arm64-apple-ios-simulator
- r - 如何将观察结果与多个类别的成员进行交叉表分析?
- jquery - 使用 laravel 通过 ajax 接收多个 id
- javascript - 在我的 HTML 文档中,当我尝试注销输入值时,它是未定义的。为什么?