gpt4 book ai didi

javascript - 将保存代码放入文本框中,然后将变量更改为该保存代码

转载 作者:行者123 更新时间:2023-12-02 23:56:09 25 4
gpt4 key购买 nike

我回来了,我尝试了一下,但没有用,有人可以帮忙吗???我已经放入了保存机制。(我必须添加额外的文本,因此这与脚本本身无关)

这是我用来测试保存机制的代码。

<!DOCTYPE html>
<html>
<body>
<button onclick="point();">points</button>
<button onclick="upgrade()">upgrade</button>
<script language="javascript">
var pointcount = 0;
var totalcliks = 0;
var upgrades = 0;
function point() {
pointcount++;
totalcliks++;
}
function upgrade() {
upgrades++;
pointcount--;
}
function load() {
var testerload = document.getElementById("savecodetextbox").value;
document.getElementById("saveshow").innerHTML = testerload;
}
var pointcounterclock = setInterval(function() {pointcounter()},100);
function pointcounter(){
document.getElementById("points-screen").innerHTML = pointcount+" points";
document.getElementById("clicktotal").innerHTML = totalcliks+" totalcliks";
document.getElementById("savecode").innerHTML = totalcliks+"a"+ pointcount+"a"+ upgrades;
}
let savecode = "1a1a1"; //grab the input for savecode here
let codes = savecode.split("a");
if(codes.length == 3){ //verify the length is correct
totalcliks = codes[1];
updates = codes[2];
pointcount = codes[3];
}
</script>
<h3 id="points-screen"></h3>
<h3 id="clicktotal"></h3>
<h3 id="savecode"></h3>
<textarea name="text_area" id="savecodetextbox" rows="4" cols="40"></textarea> <button onclick="load()">load</button>
<h3 id="saveshow"></h3>
</body>
</html>

最佳答案

我将更改您的保存代码,这样我就不必用正则表达式或时髦的分割让您感到困惑:

document.getElementById("savecode").innerHTML = totalcliks+"a"+ pointcount+"a"+ upgrades;

这意味着您的保存代码可能类似于:4a6a9

进行简单的拆分:

let savecode = "4a5a6"; //grab the input for savecode here

let codes = savecode.split("a");

if(codes.length == 3){ //verify the length is correct
totalcliks = codes[0];
upgrades = codes[1];
pointcount = codes[2];
}
至于实现变量,请在

之后重新加载游戏

关于javascript - 将保存代码放入文本框中,然后将变量更改为该保存代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55379740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com