小试ajax添加与取消监听事件

来源:互联网 发布:为什么阿里云备案 编辑:程序博客网 时间:2024/05/17 23:09
<!DOCTYPE HTML><html><head>    <script type="text/javascript" src="static/js/jquery.js"></script>    <script type="text/javascript">    var pageTimers = {} ;    function hello(){            var html = $.ajax({               type: "GET",               url: "test?t="+( new Date() ).getTime().toString(),               async: false            }).responseText;            $("#testDiv").html(html.replace(/\n/g,"<br>"));         }    $(function(){        //按钮单击时执行        $("#removeAjax").click(function(){              //Ajax返回结果              alert("OK")             <!--window.clearInterval(timer1)-->             for(var each in pageTimers){                     clearInterval(pageTimers[each]);             }            pageTimers={}         });    });    $(function(){        //按钮单击时执行        $("#addAjax").click(function(){              //Ajax返回结果              alert("OK")              console.log(pageTimers)              count=0;              for(o in pageTimers){                     count++;              }              if(count==0){                    a= window.setInterval(hello,1000);                     pageTimers[a]=a;             }         });    });    </script></head><body><div id="testDiv"><h2>测试AJAX改变文本</h2></div><button id="addAjax" type="button">添加Ajax</button><button id="removeAjax" type="button">移除Ajax</button></body></html>
原创粉丝点击