我正在尝试创建代码,当您按下按钮时,它将更改变量的值并替换一些文本。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p id="unitts">You have 0 unitts</p>
<script type="text/javascript">
var unitt = 0;
function unittIncrease() {
var unittPrev = unitt;
unitt++;
document.getElementById(unitts).innerHTML.replace("You have " + unittPrev.toString() + " unitts.", "You have " + unitt.toString() + " unitts.");
}
</script>
<button id="unittIncrease" onclick="unittIncrease();">Digitize Unitt</button>
</body>
</html>
当我按下按钮时,文本没有任何变化。 我不知道为什么这不起作用。 请帮助我!
编辑:我只有11岁, 请不要扔掉你的巫师 对我编码。
maybe you should remove your button system and add a while loop that automatically add a unit but waits one second with a setInterval function
最佳答案
我认为你应该这样写js代码
document.getElementById('unitts').innerHTML = "You have"....
而不是:
document.getElementById(unitts).innerHTML.replace("...")
关于javascript - 我需要对我的 HTML/JavaScript 代码进行一些故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347141/