This topic created in 4286 days ago, the information mentioned may be changed or developed.
Content Scripts,我定义了一个函数A(),函数A的功能为产生一个Alert。然后我在页面某处append了一个button(id为btn),然后使用document.getElementById('btn').addEventListener("click", A());来为这个button绑定一个事件,但是在我实际测试的时候发现,页面载入完毕后Alert就弹了出来,而且后续再点这个button却不会弹出Alert了。
不知道问题出在哪里,请教各位~
5 replies • 2014-09-12 17:07:59 +08:00
 |
|
1
austinchou0126 Sep 12, 2014
而且我也试过document.getElementById('btn').onclick=A();也无效
|
 |
|
2
eric_zyh Sep 12, 2014
document.getElementById('btn').onclick=A; 或 document.getElementById('btn').addEventListener("click", A);
|
 |
|
4
piglei Sep 12, 2014 via iPhone 2
- A()表达式是A函数的返回值。 - 事件绑定的应该是函数。 - 如果A方法接受参数应该在A函数里面返回另外一个函数。
|