在页面加载时,我需要一种简单的方法来显示数据库中的结果是loading..
。我没有使用jQuery来执行此操作。
我现在尝试的是:我在<div>
标记中添加了加载文字并使用JavaScript我在整个while循环后将显示设置为none
。但我根本看不到文字。
<div id="loading">Loading Results...</div>
我将上面的代码放在body标签之后。
我将以下代码放在while循环结束后。
echo "<script>document.getElementById(\"loading\").style.display = \"none\"</script>";
答案 0 :(得分:1)
在<div>
之后致电flush()
。如果您正在使用输出缓冲,它将无法正常工作。请参阅该功能手册。
如果您不希望元素在源中可见,则输出使用JS。而不是直接在html中写<div>
来写这个:
<script type="text/javascript">
document.write('<div id="loading">Loading Results...</div>');
</script>
<?php flush() ?>
<!-- output some html -->
<script type="text/javascript">
var loader = document.getElementById('loading');
loader.parentNode.removeChild( loader );
// This will not just hide the element, but remove it from the DOM, .
</script>