我将下面的代码加载到我在 test.php 文件中的内容中。 php 文件中有很多代码,因此需要一些时间来加载。当它确实加载时,“加载内容”文本仍然存在。我希望能够: - 在页面加载时显示加载符号 - 内容出现后隐藏“加载内容”文本
我该怎么做?
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(){
$("#test").load('test.php');
});
});
</script>
<div id="test"></div>
<a>Load content</a>
更新:
另外我希望它是一个链接(因为它目前在触摸设备上不起作用)- 有什么建议吗?
最佳答案
您可以嵌套 <a>
<div id="test">
内的标签标记,以便在 .load()
时将其删除功能完成或添加代码以隐藏/删除 <a>
AJAX 调用的回调函数中的标记:
<div id="test"><a>Load content</a></div>
或者在你的 JavaScript 中
$("a").click(function(){
/*Code to show loading message*/
$("#test").load('test.php', function () {
//this is a callback function that will fire after the data from test.php is loaded into the test div
$('a').hide();//or you can use .remove() to completely remove the tag
/*Code to remove the loading message*/
});
});
关于php - 使用 JQuery 在 PHP 文件中加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7854265/