1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
首先, id被聲明為<p id="identifier"></p>而不是<p id=( "Identifier")></p>。 其次,您可以使用反引號(hào)來(lái)編寫多行字符串。
請(qǐng)修改您的代碼如下
function contact() {
document.getElementById("identifier").innerHTML = `
<button class="button" onclick="email()">email</button>
<button class="button" onclick="phone()">phone</button>`;
}
function email() {
document.getElementById("identifier").innerHTML = "Email here";
}
function phone() {
document.getElementById("identifier").innerHTML = "Phone here";
}
<button class="button" onclick="contact()">Contact</button>
<p id="identifier"></p>
添加回答
舉報(bào)