2014-06-15 3 views
0

mousedown 이벤트로 var autorefresh를 지우고 싶지만 작동하지 않았습니다. 시작 간격 60초지우기 간격 자동 새로 고침

var auto_refresh = setInterval(function(){ 
$('#posts_db<?php echo $id ?>').load('data/posts_db.php'); 
}, 60000); 

합니다 (commentarea에 대한) 1,800초에 간격을 변경하는 이는 MouseDown touchstart

// Comment_on Button wechselt von 60 sek auf 30 Min 
$('#comment_on<?php echo $id ?>').bind('mousedown touchstart', function() { 
$("#comment_on<?php echo $id ?>").stop().fadeOut("fast"); 
$("#comment_off<?php echo $id ?>").stop().delay(200).fadeIn("fast"); 
$("#element<?php echo $id ?>").stop().slideDown("slow"); 
clearInterval(auto_refresh); 

// Intervall db load nach 1800 Sekunden während Eingabe 
var auto_refresh = setInterval(
function() 
{ 
$('#posts_db').load('data/posts_db.php'); 
}, 1800000); 
}); 

이는 MouseDown touchstart은 변경

$(document).ready(function() { 
$('#posts_db').load('data/posts_db.php'); 
}); 

준비 문서에

로드 60 초 뒤로 간격 (사용자가 주석을 쓰지 않기로 결정한 경우)

// Wenn Kommentar Fenster geschlossen wird Intervall wieder auf 60 Sekunden 

$('#comment_off<?php echo $id ?>').bind('mousedown touchstart', function() { 

$("#comment_off<?php echo $id ?>").stop().fadeOut("fast"); 
$("#comment_on<?php echo $id ?>").stop().delay(200).fadeIn("fast"); 
$("#element<?php echo $id ?>").stop().slideUp("slow"); 
clearInterval(auto_refresh); 


// Intervall db load nach 60 Sekunden 
var auto_refresh = setInterval(
function() 
{ 

$('#posts_db').load('data/posts_db.php'); 
}, 60000); 

}); 

auto_refresh를 1800 초로 변경하지만 다시 60 초로 변경하면 작동하지 않습니다.

+0

전역 적으로 또는 함수 외부에서 'var auto_refresh'를 초기화하십시오. –

답변

0

문제는 로컬 범위에서 auto_refresh를 계속 작성하는 것입니다. auto_refresh를 전역 적으로 선언 한 다음 로컬 버전을 만드는 대신 전역 값을 설정하면됩니다.

clearInterval(auto_refresh); 

auto_refresh = setInterval(
function() 
{ 
    $('#posts_db').load('data/posts_db.php'); 
}, 1800000); 
+0

좋아, 어떻게 든 그것은 작동하지 않았다 .. 나는 그것을 바꿨지 만 지금은 mousedown 이벤트가 간격을 변경하지 못했다. – Dave