我对所有这些都是新手,因此我决定制作一个小脚本,并且我也在使用tampermonkey,但是当我使用tampermonkey添加按钮时,onclick
似乎不起作用,我想知道是否有人知道为什么会这样吗?
// ==UserScript==
// @name BUTTONS AND NICKNAMES
// @version 0.1
// @description none right now
// @author none right now
// @description Adds button, with nickname
// ==/UserScript==
// INTRO STYLE CODES INNERHTML
var IntroGuide = '';
IntroGuide += "<button class=\"btn btn-green\" style=\"width: 45%;\" id=\"names1\" onclick=\"name1();\">NAME [1]</button>";
IntroGuide += " ";
IntroGuide += "<button class=\"btn btn-green\" style=\"width: 45%;\" id=\"names2\" onclick=\"name2();\">NAME [2]</button>";
IntroGuide += "<br><br>";
IntroGuide += "<button class=\"btn btn-green\" style=\"width: 45%;\" id=\"names3\" onclick=\"name3();\">NAME [3]</button>";
document.getElementsByClassName('hud-intro-guide')[0].innerHTML = IntroGuide;
// NINKNAMES
function name1() {
document.getElementsByClassName('hud-intro-name')[0].value = 'NAME 1 HERE';
}
function name2() {
document.getElementsByClassName('hud-intro-name')[0].value = 'NAME 2 HERE';
}
function name3() {
document.getElementsByClassName('hud-intro-name')[0].value = 'NAME 3 HERE';
}
答案 0 :(得分:0)
在此处检查代码
var IntroGuide = '';
IntroGuide += "<button class=\"hud-intro-name btn btn-green\" style=\"width: 45%;\" id=\"names1\" onclick=\"name1();\">NAME [1]</button>";
IntroGuide += " ";
IntroGuide += "<button class=\"hud-intro-name btn btn-green\" style=\"width: 45%;\" id=\"names2\" onclick=\"name2();\">NAME [2]</button>";
IntroGuide += "<br><br>";
IntroGuide += "<button class=\"hud-intro-name btn btn-green\" style=\"width: 45%;\" id=\"names3\" onclick=\"name3();\">NAME [3]</button>";
document.getElementsByClassName('hud-intro-guide')[0].innerHTML = IntroGuide;
// NINKNAMES
window.name1=function() {`enter code here`
document.getElementsByClassName('hud-intro-name')[0].innerHTML = 'NAME 1 HERE';
}
window.name2=function() {
document.getElementsByClassName('hud-intro-name')[1].innerHTML = 'NAME 2 HERE';
}
window.name3=function() {
document.getElementsByClassName('hud-intro-name')[2].innerHTML = 'NAME 3 HERE';
}