我试图在加载html页面后调用一个函数。它的工作正常,我希望函数每3秒后调用一次,因此为它插入setInterval()。但是这个函数并没有被调用。 setInterval()..的语法有任何问题吗?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(setInterval(function(){f()},3000););
function f()
{
xhttp=new XMLHttpRequest();
xhttp.open("GET","/anu/get.php",true);
xhttp.send();
xhttp.onreadystatechange = function(){
if(xhttp.readyState==4){
var Display = document.getElementById('new');
Display.innerHTML = xhttp.responseText;
}
}
}
</script>
</head>
<body>
<p id="new"> </p>
<body>
</html>
'的setInterval(函数(){F()},3000);'是一个很长的啰嗦的说法:'setInterval(f,3000);' – Quentin