所以我试图让一个页面为每个按下的按钮显示不同的段落。但是,我不断收到一些错误,其中按钮无法正确运行该功能。 例如
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 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27365900/