huoxin8226
小狐狸
小狐狸
  • UID21760
  • 注册日期2007-11-07
  • 最后登录2007-11-09
  • 发帖数2
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1491回复:2

为什么Greasemonkey中这句无效?

楼主#
更多 发布于:2007-11-08 18:06
document.getElementById("my1").click()
错误提示
  document.getElementById("my1").click is not a function
huoxin8226
小狐狸
小狐狸
  • UID21760
  • 注册日期2007-11-07
  • 最后登录2007-11-09
  • 发帖数2
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
1楼#
发布于:2007-11-08 18:06
我不是要定义,我是要调用这个方法,因为直接调用html里面的脚本函数出错
不过基本解决了,我用document.body.setAttribute("onload","javascript:XXX")把调用写上去了
wushi777
非常火狐
非常火狐
  • UID12365
  • 注册日期2006-04-17
  • 最后登录2011-04-13
  • 发帖数817
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
2楼#
发布于:2007-11-08 18:06
GM用XPCNativeWrapper对很多对象进行了包装。所以,有些访问方式不能工作正常。
比如:

Items like frames, form elements, and so on can be referenced by name in normal JavaScript. XPCNWs cannot reference items by name. Use the namedItem method.

With a <input name="foo"> in the form:

form.foo;                       // does not work
form.elements.namedItem('foo'); // works

The same goes for frames:

window.framename;               // does not work
window.frames['framename'];     // works


详细内容,可以查看http://wiki.greasespot.net/XPCNativeWrapper

如果你要定义一个功能可以试试下面的方式:

var e = document.getElementById("id");
if(e)
e.addEventListener("click",function(){
//some statements
},true);
游客

返回顶部