【发布时间】:2012-01-23 16:47:24
【问题描述】:
如何将参数传递给声明为 something = function(){};
的函数window.prototype.initInterface = function(){
this.mainPane = document.createElement('div');
this.mainPane.style.border="5px solid grey";
this.mainPane.style.margin="0px";
this.mainPane.style.width="420px";
this.mainPane.style.height="600px";
this.exitButton = document.createElement('input');
this.exitButton.setAttribute("type", "button");
this.exitButton.setAttribute("value", "exit");
this.exitButton.onclick = function(){
document.body.removeChild(this.mainPane);
};
this.mainPane.appendChild(this.exitButton);
document.body.appendChild(this.mainPane);
}
当用户按下退出按钮时,我想从 html 页面的正文中删除 mainPane。
this.exitButton.onclick = function(this.mainPage){
document.body.removeChild(this.mainPane);
};
不工作
我该怎么做?
【问题讨论】:
-
window.prototype?我不认为window是构造函数... -
谢谢,下面的工作: var self = this; this.exitButton.onclick = function(){ document.body.removeChild(self.mainPane); };
标签: javascript function parameters prototype