我有一個JavaScript函數(shù),每2000ms調(diào)用一次。我想停止此操作,以便我可以讓用戶在頁面上執(zhí)行其他操作,而無需再次調(diào)用它。這可能嗎?這是每2000ms調(diào)用一次的函數(shù):window.setInterval(function getScreen (sid) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("refresh").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","getScreen.php?sid="+<?php echo $sid; ?>,true); xmlhttp.send(); },2000);
如何在JavaScript中停止window.setInterval?
慕容708150
2019-10-21 09:50:58