나는 jquery 및 javascript를 처음 사용합니다. 매초마다 1 씩 증가하는 자바 스크립트에서 변수를 설정해야합니다. 이를 위해 다음을 수행했습니다.
function run(){
timer++;
}// run ends here
setInterval(run,1000);
변수 값이> 5이면 누군가가 html 페이지에서 iframe을 가리킬 때마다 ajax 요청이 완료되도록 코드를 활성화하고 싶습니다.
sinigle ajax 요청 후 timer = 0을 재설정하고 싶습니다.
if(timer>5){
$("iframe").hover(function(){
$.ajax({
url: 'http://localhost/test.html',
cache: false,
data: 'html',
success: function(data,status) {
}
});
});
timer=0;
}
이 프로세스는 다시 반복되어야하며 카운터는 0에서 5까지 다시 시작되어야하며 ajax 요청 기능이 다시 활성화되어야합니다.
다음은 한 곳에서 전체 코드입니다.
<script>
var i = 0;
var timer=0;
function run(){
timer++;
}// run ends here
setInterval(run,1000);
if(timer>5){
$("iframe").hover(function(){
$.ajax({
url: 'http://localhost/test.html',
cache: false,
data: 'html',
success: function(data,status) {
}
});
});
timer=0;
}
</script>
나는 많이 시도하고 많이 봤지만 해결책을 알아낼 수 없었습니다.
이 시도 :
var timer=0;
function run(){
timer++;
if(timer == 5){
$("iframe").on('mouseenter', function(){
$.ajax({
url: 'http://localhost/test.html',
cache: false,
data: 'html',
success: function(data,status) {
timer=0;
$('iframe').off('mouseenter')
}
});
});
}
}// run ends here
setInterval(run,1000);
iframe에 이미 mouseenter 이벤트가있는 경우 .off('mouseenter')
해당 바인딩을 삭제합니다.
Ian이 제안했듯이 특정 바인딩을 해제 할 수 있도록 이벤트 이름을 지정할 수 있습니다.
그렇게하려면 바인딩 / 바인딩 해제 할 때 점을 사용하십시오.
$("iframe").on('mouseenter.timer',...)
$('iframe').off('mouseenter.timer')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다