[英]how to change innerHtml by adding a integer value to element?
I build a Scoreboard我建立一个记分牌
what it does when someone click the +500 button it will add 500 to the value in the score board ie it will add 500 to the value of p tag当有人单击 +500 按钮时它会做什么,它将在记分板上的值上加 500,即它将在 p 标签的值上加 500
<div class="box">
<h2>Teams</h2>
<div class="score">
<p id="p1" class="lead">230</p>
</div>
/div>
<button id="b1">+500</button>
JavaScript for it JavaScript 为它
var myScore = document.getElementById("b1");
myScore.onclick = function () {
var newScore = document.getElementById("p1").innerHTML;
var value = newScore + 500;
document.getElementById("p1").innerHTML = value;
};
but this is showing me 230500 instead of 730 .但这向我显示230500而不是730 。 how to change my inner html value 230 in integer form ??如何以整数形式更改我的内部 html 值 230 ?
Right now, you're adding an integer to a string, so you're making a string concatenation.现在,您正在将一个整数添加到一个字符串中,因此您正在进行字符串连接。
Change改变
var value = newScore + 500;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.