에 의해 내가 여기에 몇 가지 코드를하려 할 때,자바 스크립트 : 객체의 기능이 호출이 온 클릭
var cat={
col:"Red",
getCol:function(){
document.writeln(this.col);
}
}
function getCol(){
document.writeln(cat.col);
}
$(function(){
$("#button1").click(cat.getCol);
$("#button2").click(getCol);
})
을 정의되지하지만 button2를 들어, 단추 1은 "레드"undefined
을 받고 있습니다. 누군가 왜 저에게 말할 수 있습니까? 내가 $("#button1").click(cat.getCol());
로 변경하면 cat.getCol
의 몸이 this
을 사용하기 때문에
는 그리고, 나는 내가 필요로 "레드"... 모든
$("#button1").click(cat.getCol);
의
가능한 중복 [무엇 내 이벤트 처리기 잘못?] (http://stackoverflow.com/questions/6804622/whats-wrong-with-my-event-handler) –
FYI,'$ ("# button1"). click (cat.getCol());'버튼 클릭이 아니라 즉시'cat.getCol'을 실행합니다. –
감사합니다. 그것은 '이'사물에 관한 것이어야합니다. – TKL