所以我试图使页面为每个按下的按钮显示不同的段落。但是,在按钮无法正确运行功能的地方,我仍然遇到一些错误。
防爆
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = "When I put more "" it fails in other words it will not write this part."
}
<button onclick="examplefunction()">Change Paragraph</button>
<p id="paragraphtobechanged"></p>
最佳答案
它应该是:
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = "When I put more \"\" it fails in other words it will not write this part."
}
您需要转义双引号。或者,您可以执行以下操作:
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = 'When I put more "" it fails in other words it will not write this part.'
}
关于javascript - 更改段落时出现Javascript错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27365900/