📜  如何使用 javascri[t - Java 代码示例创建一个按钮

📅  最后修改于: 2022-03-11 14:52:23.511000             🧑  作者: Mango

代码示例1
// 1. Create the button
var button = document.createElement("button");
button.innerHTML = "Do Something";

// 2. Append somewhere
var body = document.getElementsByTagName("body")[0];
body.appendChild(button);

// 3. Add event handler
button.addEventListener ("click", function() {
  alert("did something");
});

/* Read 

https://css-tricks.com/use-button-element/
*/