【问题标题】:Trying to make a Alert button in tampermonkey试图在 Tampermonkey 中创建一个警报按钮
【发布时间】:2020-03-04 04:57:39
【问题描述】:

我一直试图让一个警报按钮在 Tampermonkey 中工作,但我似乎没有让它工作。 这是我的脚本;

var button = document.createElement("Button");
button.innerHTML = "Title";
button.style = "top:15px;left:15px;position:absolute;z-index:99999; width:50px; height 50px; background_color; ff0000";
button.onclick = "alert('Test Alert')"
document.body.appendChild(button);

【问题讨论】:

    标签: javascript tampermonkey jquery-click-event


    【解决方案1】:

    您只能将一个函数分配给onclick。如果你分配一个字符串,点击发生时不会执行任何函数:

    var button = document.createElement("Button");
    button.innerHTML = "Title";
    button.style = "top:15px;left:15px;position:absolute;z-index:99999; width:50px; height 50px; background_color; ff0000";
    button.onclick = () => alert('Test Alert');
    document.body.appendChild(button);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 2021-04-08
      • 2023-03-23
      • 2020-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多