有什么方法可以在 PHP 页面加载后 10 秒调用一个函数。 (不使用 HTML。)
最佳答案
PHP 是一种服务器端脚本语言。如果您需要检查客户端是否已经加载了某些内容,您将需要一种客户端脚本语言,例如 JavaScript.
您可能需要根据您的目的使用 jQuery 来简化事情。
jQuery is a slow JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
首先,下载jQuery .在 HTML 的 head 标签中,添加:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// Check if the page has loaded completely
$(document).ready( function() {
setTimeout( function() {
$('#some_id').load('index.php');
}, 10000);
});
</script>
在您的 HTML 正文中,添加以下内容:
<div id="some_id"></div>
关于php - 如何在页面加载 10 秒后调用 PHP 函数(不使用 HTML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1333434/