这个问题在这里已有答案:
我知道如何使用userscript创建一个按钮,但我不知道如何使用usercript将函数附加到按钮。如何使用usercript将功能附加到按钮?我还想用usercript为按钮添加一个“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()
用usercript将函数附加到按钮
button.addEventListener("click", clickMe, false);