的函數如何將參數傳遞給聲明爲something = function(){}的函數?如何將參數傳遞給聲明如left = 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'是一個構造函數... –
[我如何在事件處理程序中訪問'this'](http://stackoverflow.com/questions/7696672/how-can-i -access-this-in-an-event-handler) –
謝謝,下面的工作: var self = this; this.exitButton.onclick = function(){ \t document.body.removeChild(self.mainPane); }; –