gpt4 book ai didi

Javascript 函数在两个特定值之间反转

转载 作者:行者123 更新时间:2023-12-03 12:34:37 25 4
gpt4 key购买 nike

当我根据值是增加还是减少来更改数字输入框中的值时,它应该根据它是增加还是减少来更改“总计”(其花费的总点数)

但是,当我在“9”和“10”之间更改时,它会反转(如果我降低数字,它也会降低总数,反之亦然,当它应该做相反的事情时)

测试站点:http://alboneon.pentacore.se/您必须登录用户名:stackoverflow 和密码:1234,然后按创建字符访问它

输入框:

<div style="width: 45%;right: 0; float: right; padding-right: 10px; text-align: right;">
<!--<button onchange="calcstat()">Randomize</button>-->Stat <br/>
<input id="strcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="dexcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="concrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="intcrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="wiscrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<input id="chacrt" type="number" max="15" min="8" value="8" onchange="calcstat(this.id, this.value)"><br/>
<div id="total">27</div>
</div>

Javascript:

function calcstat(id, values) {
var change = 0 * 1;
if (oldscores[id] < values) {
//change = values - 8;
change = 1 * 1;
} else if (oldscores[id] > values) {
//change = -Math.abs(oldscores[id] - 8);
change = change-1;
}
atributescore = atributescore - change;
oldscores["strcrt"] = document.getElementById("strcrt").value;
oldscores["dexcrt"] = document.getElementById("dexcrt").value;
oldscores["concrt"] = document.getElementById("concrt").value;
oldscores["intcrt"] = document.getElementById("intcrt").value;
oldscores["wiscrt"] = document.getElementById("wiscrt").value;
oldscores["chacrt"] = document.getElementById("chacrt").value;
document.getElementById("total").innerHTML = atributescore;

最佳答案

function calcstat(id, values) {
var change = values - oldscores[id];
atributescore = atributescore - change;
oldscores["strcrt"] = document.getElementById("strcrt").value;
oldscores["dexcrt"] = document.getElementById("dexcrt").value;
oldscores["concrt"] = document.getElementById("concrt").value;
oldscores["intcrt"] = document.getElementById("intcrt").value;
oldscores["wiscrt"] = document.getElementById("wiscrt").value;
oldscores["chacrt"] = document.getElementById("chacrt").value;
document.getElementById("total").innerHTML = atributescore;
}

关于Javascript 函数在两个特定值之间反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23781966/

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