首先,让我解释一下我想要做什么:我想为视频游戏制作一个脚本,计算游戏中的多少钱,并创建一个元素来显示它。跟踪金钱部分很容易,但显然制作元素就像我试图做的最令人困惑的事情一样。
Chrome 控制台的 Lightshot 屏幕截图:https://prnt.sc/shszc2 屏幕截图中蓝色突出显示的行在执行两次后出现错误。我用红色框住了错误消息。
我将从我拥有的脚本中删除一些代码,主要针对对我想要帮助的问题很重要的代码,省略我理解的代码。
还要注意,我对在Javascript中生成图形非常陌生,所以如果我制作元素的方式很可怕,那么这是因为我只是不断尝试随机的废话,直到某些东西似乎有效并坚持使用任何东西。
// The elements that I created. Again i know next to nothing about elements, so the only thing that I
// know will work is this catastrophe.
var initialDiv = document.getElementById('onecup');
mainText = initialDiv.appendChild(document.createElement('mainText'));
mainText.style.position = 'absolute';
mainText.style.left="50%";
mainText.style.top="64px"
mainText.style.width = "290px";
mainText.style.height = "160px";
mainText.style.color = "white";
mainText.style.zindex = 1;
mainText.style.fontSize = "18px"
trackerBack = mainText.appendChild(document.createElement('trackerBack'));
trackerBack.style.position = 'absolute';
trackerBack.style.left="-200px"
trackerBack.style.top="0px"
trackerBack.style.width = "400px";
trackerBack.style.height = "160px";
trackerBack.style.backgroundColor = "black";
trackerBack.style.opacity = ".20"
trackerBack.style.zindex=1;
diffTotal = trackerBack.appendChild(document.createElement('diffTotal'));
diffTotal.id = "diffTotal"
diffTotal.style.position = 'absolute';
diffTotal.style.top="20%"
diffTotal.style.left="40%";
diffTotal.style.color = "rgba(255,255,255,255)";
diffTotal.style.opacity = "1"
diffTotal.style.zindex = 2;
diffTotal.style.fontSize = "30px"
diffFielded = diffTotal.appendChild(document.createElement('diffFielded'));
diffFielded.id = "diffFielded"
diffFielded.style.position = 'absolute';
diffFielded.style.top="-15px"
diffFielded.style.left="0px";
diffFielded.style.color = "rgba(255,255,255,255)";
diffFielded.style.opacity = "1"
diffFielded.style.zindex = 2;
}
阿晨1998
相关分类