我有一个div remaining

remaining.innerHTML = "You have NUMBER remaining SECOND VARIABLE"

我知道我可以通过执行remaining.innerHTML = "new string"来更改innerHTML,但是我想知道如何使用JavaScript在不知道NUMBER的索引或值的情况下如何将NUMBER的新值注入到innerHTML中?但是,不变的内容(例如You haveremaining)是恒定的。

最佳答案

使用字符串串联:

var number = 1;
var secondVariable = 2;

remaining.innerHTML = "You have " + number + " remaining " + secondVariable;
// results in "You have 1 remaining 2";

关于javascript - 插入item.innerHTML,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5404961/

10-16 17:51