尝试这个:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function timer(){
$.post( "process.php", function( data ) {
$('#times').append('<li>'+data+'</li>');
});
}
setInterval(function(){timer()},1000);
});
</script>
</head>
<body>
<ul id="times"></ul>
</body>
</html>
并把它放在你的 process.php
文件:
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://www.time.is/');
foreach($html->find('#clock0') as $element){
echo $element->plaintext;
}
?>
这是我的测试结果:
- 上午11:15:43
- 上午11:15:46
- 上午11:15:51
- 上午11:15:53
- 上午11:15:53
- 上午11:16:10
- 上午11:15:52
- 上午11:15:42
- 上午11:16:09
- 上午11:16:17
- 上午11:16:12
笔记:
1-建议您将间隔从1000毫秒(1秒)更改。
2-不要忘记使用 clearInterval()
重复特定后。