我想在这里的一些代码是不明确的,的Javascript:在目标函数调用时通过的onclick
var cat={
col:"Red",
getCol:function(){
document.writeln(this.col);
}
}
function getCol(){
document.writeln(cat.col);
}
$(function(){
$("#button1").click(cat.getCol);
$("#button2").click(getCol);
})
但我得到undefined
为Button1,“红色”的按钮2。有人能告诉我为什么吗?
如果我把它变成$("#button1").click(cat.getCol());
,我拿到了“红”我需要......
的可能重复[这有什么错我的事件处理程序?(http://stackoverflow.com/questions/6804622/whats-wrong-with-my-event-handler) –
仅供参考,'$(“#button1”)。click(cat.getCol());'立即执行'cat.getCol',而不是按钮点击。 –
谢谢。它应该是关于'这'的东西。 – TKL