HTML 按钮不执行任何操作和意外的代码



我做了一个简单的"不要按按钮"游戏,有两个错误(另一个问题不同(意外的文本这是我写的代码:

<body>
<h1>Don't press the button</h1><br/>
<p>DON'T PRESS THE BUTTON</p>
<div class="round-button">
<button type="button" onclick="alert('Why Did You Press Me. The next button you click will have consequences')">Don't Click Me</button>
</div>
<div class="hint-text">
<p><b>V V V V</b></p>
</div>
<div class="round-button button2">
<button type="button" onclick="alert('Ok, this is your last chance. Don't press anymore buttons... not that there are any')">NOT A BUTTON</button>
</div>

这是网页中的代码:

<body>
"Don't Press the Button "
<h1>Don't press the button</h1><br/>
<p>DON'T PRESS THE BUTTON</p>
<div class="round-button">
<button type="button" onclick="alert('Why Did You Press Me. The next button you click will have consequences')">Don't Click Me</button>
</div>
<div class="hint-text">
<p><b>V V V V</b></p>
</div>
<div class="round-button button2">
<button type="button" onclick="alert('Ok, this is your last chance. Don't press anymore buttons... not that there are any')">NOT A BUTTON</button>
</div>
</body>

正如@K Scandrett在评论中所说;不要"导致了您的问题。你需要把一个"以前,像这样:

onclick="alert('Ok, this is your last chance. Don't press anymore buttons... not that there are any')">NOT A BUTTON</button>
</div>
</body> 

转义符用于删除单个字符的特殊含义,而保留文字值。在这种情况下;不要"导致程序将其读取为字符串的末尾,并忽略该行的其余部分。这就是为什么你会出现这个错误:

{";消息":"Uncaught SyntaxError:缺少(}

最新更新