单击div时停止自动刷新 [英] stop auto refresh when clicked on a div

查看:126
本文介绍了单击div时停止自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击特定的div时,我想停止自动刷新,这就是我目前的代码

i would Like to stop auto refresh when i click on a specfic div this is how my code looks like at the moment

jquery.js

var documentInterval;
$(document).ready(function(){
  documentInterval setInterval(function(){
      $('#show_here').load('fetch_something.php')
  }, 3000);
});

$('#stop_auto_refresh').click(function(){
  clearInterval(documentInterval);
});

index.php

<div id="show_here"></div>
<div id="stop_auto_refresh" onclick="documentInterval()">Click To Stop Auto Refresh</div>

我想在单击id stop_auto_refresh时停止自动刷新 这可能吗?

I would like to stop auto refresh when click on the id stop_auto_refresh is this possible ?

推荐答案

使用clearInterval(intervalReference)清除间隔.由于使用的是jQuery,因此可以使用.click() jQuery api添加单击处理程序.

Intervals are cleared as using the clearInterval(intervalReference). You can add a click handler using the .click() jQuery api since you are using jQuery.

var documentInterval;

$(document).ready(function() {
   documentInterval = setInterval(function(){
      $('#show_here').load('fetch_something.php')
   }, 3000);

   $('#stop_auto_refresh').click(function(){
     clearInterval(documentInterval) 
   })

});    

这篇关于单击div时停止自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆