【发布时间】:2009-02-15 15:20:57
【问题描述】:
这是我的脚本代码:
// ==UserScript==
// @name test
// @description test
// @include http://*
// @copyright Bruno Tyndall
// ==/UserScript==
var main = function() {
var b = document.getElementsByTagName('body')[0];
var t = document.createElement('div');
t.innerHTML = '<a href="javascript:void(0);" style="color:white;">Hello World</a>';
t.style.position = 'absolute';
t.style.zIndex = 1000;
t.style.bottom = '5px';
t.style.right = '5px';
t.firstChild.setAttribute('onclick', 'test();');
b.appendChild(t);
}
var test = function() {
alert("Hello World");
}
main();
我唯一的问题是当点击 Hello World 时页面找不到 test() 函数。请告诉我,我不必通过innerHTML'ing 函数到this 之类的页面上来解决它。还有其他方法吗?
谢谢。
【问题讨论】:
标签: javascript firefox scope greasemonkey