gpt4 book ai didi

JavaScript 值未在 console.log 中求和

转载 作者:行者123 更新时间:2023-11-28 17:52:06 26 4
gpt4 key购买 nike

我想对从跨度中获取的用户值求和。这是我的 JS 代码:

var attackerStr = document.getElementById('attackerStr').innerText;
var attackerDex = document.getElementById('attackerDex').innerText;
var attackerVit = document.getElementById('attackerVit').innerText;
var attackerIntel = document.getElementById('attackerIntel').innerText;

var userStr = document.getElementById('userStr').innerText;
var userDex = document.getElementById('userDex').innerText;
var userVit = document.getElementById('userVit').innerText;
var userIntel = document.getElementById('userIntel').innerText;

console.log((attackerStr - userStr)+(attackerDex - userDex)+(attackerVit - userVit)+attackerIntel - userIntel);

正在减去该值,但未求和。该号码仅显示在另一个号码旁边,如下所示:213075

最佳答案

对像这样的所有字段使用 parseInt 函数

var attackerStr = parseInt(document.getElementById('attackerStr').innerText);

关于JavaScript 值未在 console.log 中求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45274453/

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