将函数添加到用usercript [duplicate]制作的按钮

问题描述 投票:-3回答:1

这个问题在这里已有答案:

我知道如何使用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()
javascript function button userscripts
1个回答
-2
投票

用usercript将函数附加到按钮

button.addEventListener("click", clickMe, false);
© www.soinside.com 2019 - 2024. All rights reserved.