Javascript HTML onclick处理程序未触发innerHTML更改

Javascript HTML onclick处理程序未触发innerHTML更改,javascript,html,onclick,innerhtml,Javascript,Html,Onclick,Innerhtml,我正在做一个饥饿游戏模拟,这是我的代码: console.log(data); document.getElementById("playarea").innerHTML = data; console.log(document.getElementById("playarea").innerHTML); 当我将变量数据记录到控制台时,它会给出以下结果 <img src='img/fight.png'><br /> You grabbed a loaf of bread

我正在做一个饥饿游戏模拟,这是我的代码:

console.log(data);
document.getElementById("playarea").innerHTML = data;
console.log(document.getElementById("playarea").innerHTML);
当我将变量
数据
记录到控制台时,它会给出以下结果

<img src='img/fight.png'><br />
You grabbed a loaf of bread out of the crate, the girl from 9 comes to you for a fight.
<br />
<button onclick=fight('You grabbed a loaf of bread out of the crate, the girl from 9 
comes to you for a fight.','','',4,1,2)>
Punch in the head
</button><br />
<button onclick=fight('You grabbed a loaf of bread out of the crate, the girl from 9 
comes to you for a fight.','','',4,1,2)>Punch in the chest</button><br />
onclick
中,它将每个单词分开,并将它们视为变量

如何使
innerHTML
与数据变量相同?

更改(在数据内)


进入



如果值仅为一个单词,则只能使用引号。

+1;这就是答案。为了详细说明这一点,当您省略引号时,附加的单词将被解析为
的属性,因此
抓取了=“”a=“”
,等等。谢谢,它现在可以正常工作了。我必须在字符串中使用两种类型的引号,所以我在数据变量中添加了+““+”,效果非常好!最好使用jQuery并忘记引号问题。$(“#playrea”).html(数据)
<img src="img/fight.png"><br>
You grabbed a loaf of bread out of the crate, the girl from 9 comes to you for a fight.
<br>
<button onclick="fight('You" grabbed="" a="" loaf="" of="" bread="" out="" the=""  
crate,="" girl="" from="" 9="" comes="" to="" you="" for="" 
fight.','','',4,1,2)="">
Punch in the head
</button><br>
<button onclick="fight('You" grabbed="" a="" loaf="" of="" bread="" out="" the="" 
crate,="" girl="" from="" 9="" comes="" to="" you="" for=""    
fight.','','',4,1,2)="">
Punch in the chest
</button><br>
<button onclick=fight('You grabbed ...','','',4,1,2)>
<button onclick="fight('You grabbed ...','','',4,1,2)">