<!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>
小试ajax添加与取消监听事件
最新推荐文章于 2023-01-19 10:05:47 发布