如何從靜態html事件處理程序訪問util.log()方法?事件處理程序無法訪問JavaScript中的Object方法
換句話說,當我點擊複選框時,我喜歡調用util.log方法。
onclick =「util.log(\'hey \')」< - 如何在這裏重寫事件函數?
我知道所有的答案在這裏是正確的,但是可以在插入html到innerHTML的時候訪問本地方法嗎?
謝謝
var utilities = function() {
var util = this;
util.log = function(msg){
alert(msg);
};
var p = document.createElement('p');
p.innerHTML = '<input type="checkbox" onclick="util.log(\'hey\')" value="1">Check me';
// this part has to be plain html, because there is this table generator class
// will insert this to cell as innerHTML. That's why I can't change the table class.
};
你想點擊複選框時會顯示「嗨」的提示? – 2010-02-05 02:30:35
是的,但最終,如何從硬編碼事件調用對象方法? – Nizzy 2010-02-05 02:32:45