未访问全局变量,未运行代码

Global variables not being accessed, code not being ran

本文关键字:代码 运行 全局变量 访问      更新时间:2023-09-26

>第一篇文章,对不起,如果我做错了。

var tierArray = [390, 520, 750, 975, 1350, 1820, 3250];
var rand = Math.floor((Math.random() * 6) + 1);
var rp;
var skinName = document.getElementById("skinName");
var skinRP = document.getElementById("skinRP");
var totalRP = document.getElementById("totalRP");
var totalMG = document.getElementById("totalMG");
var total = parseInt(totalRP.value);
var mg = parseInt(totalMG.value);
var array390, array520, array750, array975, array1350, array1820, array3250 = [];
var skinImg = document.getElementById("skin");
var activeArray;
function roll() {
    mg += 490;
    rp = tierArray[rand];
    total += rp;
    skinName.value = "hello";
    skinRP.value = rp;
    totalRP.value = total;
    totalMG.value = mg;
}
我的

页面在将所有变量移动到全局范围之前工作,以便它们可以用于其他方法,现在它们已被移动,代码无法运行,并且我的 JSLint 没有发现问题,我错过了什么吗?

运行

代码时,函数外部的元素不会加载,这可能是因为您首先将脚本实现到页面,然后插入HTML DOM元素。

<head>
<script>         < The elements dont exist
<body>
<element>        < The elements exist
<script>         < Your script