我想僅使用JavaScript創建邊欄,但無法將關閉按鈕添加到div。 我試過這個:JS - 如何使用appendChid將按鈕添加到div中
var sideb = document.createElement("Div");
sideb.style.height = "100%";
sideb.style.width = "0px";
sideb.style.backgroundColor = "rgb(30,30,30)";
sideb.style.top = "0px";
sideb.style.right = "0px";
sideb.style.margin = "0px";
sideb.style.padding = "0px";
sideb.style.position = "fixed"
document.body.appendChild(sideb);
var close = document.createElement("Button");
close.innerText = "close";
close.onclick = close;
document.body.sideb.appendChild(close)
但它不工作。
呵呵呵你是對的 – Osama
昆汀評論解碼。請寫幾行關於你的答案,而不是僅僅給出工作代碼。 –