how to change innerHtml by adding a integer value to element?

前端 未结 1 1500
Happy的楠姐
Happy的楠姐 2021-01-22 15:53

I build a Scoreboard

what it does when someone click the +500 button it will add 500 to the value in the score board i.e it will add 500 to the value of p tag



        
1条回答
  •  被撕碎了的回忆
    2021-01-22 16:06

    Right now, you're adding an integer to a string, so you're making a string concatenation.

    Change

     var value = newScore + 500;
    

    to

     var value = parseInt(newScore,10) + 500;
    

    0 讨论(0)
提交回复
热议问题