카운트를 시작하고 단추를 클릭 할 때 중지 할 타이머를 만들려고합니다. here에서 수정 한 코드가 온라인에 있지만 jQuery 게시 메서드를 호출 할 때 불법 호출 오류가 발생합니다. 나는 그것이 범위 문제라고 확신한다. 그러나 나는 그 주변의 최선의 방법이 확실치 않다. 내 수정 된 코드는 아래와 같습니다.개체 내에서 jQuery 호출
var timer={
init:function(id){
this[id]={
obj:document.getElementById(id)
}
},
start:function(id){
var obj=this[id];
obj.srt=new Date();
clearTimeout(obj.to);
this.tick(id);
$("#climbTimer").unbind();
$('#climbTimer').click(function(){timer.finalStop('climbTimer'); return false;});
if ($('#'+id).html().indexOf('Start') != -1)
$('#'+id).html('Stop Ascend<br><span id="elapsedTime">0.00</span>');
},
stop:function(id){
\t clearTimeout(this[id].to);
},
finalStop:function(id){
\t clearTimeout(this[id].to);
\t
\t $.post('php/climbTime.php', {team: document.getElementById('team').value, roundNum: document.getElementById('round').value, time: document.getElementById('elapsedTime')});
},
tick:function(id){
this.stop(id);
var obj=this[id],sec=(new Date()-obj.srt)/1000,min=Math.floor(sec/60),sec=sec%60;
$('#elapsedTime').html(sec>9?sec:''+sec);
obj.to=setTimeout(function(){ timer.tick(id); },100);
}
\t
}
점점 더 자세한 오류 메시지가 나타날 수 있습니까? – amphetamachine
'timer.finalStop ('climbTimer') 대신'timer.finalStop (id);'가 필요합니다. 또한 더 이상 사용되지 않는'.unbind()'를 사용하지 말고'.off ('click')'을 사용하십시오. – trincot