【发布时间】:2019-02-19 20:56:45
【问题描述】:
我知道如何使用用户脚本创建按钮,但我不知道如何使用用户脚本将功能附加到按钮。如何使用用户脚本将功能附加到按钮?我还想为带有用户脚本的按钮添加一个“id”。我怎么做?谢谢。
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);
function clickMe() {
alert("Hi");
} //end of function clickMe()
【问题讨论】:
标签: javascript function button userscripts