两个问题。
当我加载到div
时通过 jQuery 文件 .load()
$('.class').click(function(){
$(this).load("file.php");
});
file.php
正在正确加载,但每当我单击它时(无论在哪里,就在 file.php
区域),页面都会闪烁。比如点击页面刷新之类的。有办法防止这种情况吗?
此外,该页面的位置始终相对于 div。为什么不position: absolute;
上body
在单独的 css 文件中 file.php
为 file.php
工作?我想重置 file.php
的位置位于网站顶部(不是 z-index)。谢谢。
最佳答案
你的代码
$('.class').click(function(){
$(this).load("file.php");
});
表示每当您单击该 div 时,都会(重新)加载内容。
您可能想使用 jQuery 的 one方法代替
$('.class').one("click", function(){
$(this).load("file.php");
});
它只会在您第一次点击 div 时执行。
至于位置,我们需要查看代码。可能您的父元素之一具有 position:relative
?
关于javascript - 点击页面时页面闪烁 | jQuery .load(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32772529/