我是否在 JS innerHTML 中正确使用了引号?

Am I using quotation marks properly in JS innerHTML?

var foo = 100;
        var firstCell = newRow.firstChild.innerHTML = "<button id='removeBtn' onclick='removeRow("+ foo +")'>X</button>";

我有这么一小行代码,它将一个按钮插入到 table 单元格中,然后为其分配一个带有参数 (foo) 的函数。即使它有效,我的代码编辑器 brackets 也不会像 innerHTML 的其余部分那样显示“+ foo +”部分。我认为这与我的引号混淆有关,但我不确定如何解决这个问题。这是个问题还是我应该这样离开?

您可以转义双引号,以便将它们放在 onclick 中。

... =  "<button id='removeBtn' onclick='removeRow(\""+ foo +"\")'>X</button>";