在您再次将此标记为重复之前,我只想说,我已经转到另一个问题,并阅读了整个问题,并尝试在我的一端创建相同的结果。我尝试将事件侦听器添加到我的按钮,但它仍然不起作用。因此,我恳请你给其他人一些时间来回答我的问题,然后再标记为重复或删除它。
var button = document.createElement("BUTTON"); // Create a <button> element
var text = document.createTextNode("CLICK ME"); // Create a text node
button.appendChild(text); // Append the text to <button>
document.body.appendChild(button);
button.addEventListener("click", clickMe, false);
function clickMe() {
alert("Hi");
} //end of function clickMe()
发布于 2019-02-20 05:18:27
这将添加按钮的id
var button = document.createElement("BUTTON");
button.setAttribute("id", "buttonid");
// Create a <button> element
var text = document.createTextNode("CLICK ME"); // Create a text node
button.appendChild(text); // Append the text to <button>
document.body.appendChild(button);
button.addEventListener("click", clickMe,false);
function clickMe() {
alert("Hi");
} //end of function clickMe
https://stackoverflow.com/questions/54775010
复制相似问题