jQuery .hide 函数不起作用
大家好,希望你们能帮忙。
我有一个非常简单的 jQuery 隐藏函数,它可以工作,但是一夜之间出现了一些 bugInTheRom,并且不再起作用。实际上,我正在尝试添加一些在加载某些 SWF 时可见的“耐心”警告。
这是我在 部分中的调用...
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript">
function hidden() {
$('.patience').hide();
};
window.onload=hidden;
</script>
这是它影响的类...
<p class="patience">Please be patient, the interactive book below and the PDF links may take a while to fully load.</p>
以及关联的 CSS...
.patience {
visibility: visible;
background-color: #CCC;
border: 1px solid #000;
margin-right: 10px;
margin-left: 10px;
}
任何想法为什么它不会在整个 SWF 后隐藏已加载?
我的谢谢。 右
Hy guys and hope you can help.
I have a very simple jQuery hide function that was working but some bugInTheRom has occured overnight and it no longer does. Effectively I'm trying to add a 'Patience' warning visible whilst some SWF loads.
Here's my call in the <head>
section...
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript">
function hidden() {
$('.patience').hide();
};
window.onload=hidden;
</script>
and here's the class it affects...
<p class="patience">Please be patient, the interactive book below and the PDF links may take a while to fully load.</p>
and the associated CSS...
.patience {
visibility: visible;
background-color: #CCC;
border: 1px solid #000;
margin-right: 10px;
margin-left: 10px;
}
Any ideas why it doesn't hide once the whole of the SWF has been loaded?
My thanks.
R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您遇到问题,我会切换到:
这可能有助于一切正常初始化。
我不确定我是否理解 SWF 是如何相关的...也许您的意思是说
swf_elem.onload
或其他内容而不是window.onload
?If you're having problems, I would switch to:
which might help everything initialize properly.
I'm not sure I understand how the SWF is related... perhaps you meant to say
swf_elem.onload
or something instead ofwindow.onload
?一方面,将
window.onload=hidden;
更改为$(function(){hidden();});
我建议的新方法是使用 jQuery 版本的
文档就绪
,确保您可能想要影响的元素已加载并可以使用。另外,我在您的代码中没有看到任何将此
hidden()
函数连接到任何 SWF 加载的内容请参阅小提琴: http://jsfiddle.net/maniator/XX8ym/
For one thing change
window.onload=hidden;
to$(function(){hidden();});
The new way i suggested is using jQuery's version of
document ready
which makes sure that the elements that you might want to affect are loaded and can be used.Also i see nothing in your code which connects this
hidden()
function to any SWF loadSee Fiddle: http://jsfiddle.net/maniator/XX8ym/
首先 -
window.onload
是放置此处理程序的正确位置 - 与$(document).ready()
不同,它会等到所有子帧、图像等,已加载。我不知道的是
window.onload
是否也会等待 SWF 对象加载。如果它不等待SWF,那么效果将是您的
.patience
div将过早消失,因为其余的页面将完成加载。如果它确实等待,但你的 div 根本没有消失,这表明你只是在真正的 JS 代码中的某个地方遇到了一个小错误,导致
.hide()
永远不会消失叫。既然你说过 div 没有消失,我建议你遇到后一个问题,在这种情况下,使用 JS 调试器几分钟应该会揭示(没有双关语)问题。
Firstly -
window.onload
is the right place to put this handler - unlike$(document).ready()
it will wait until all sub-frames, images, etc, have loaded.What I don't know is whether
window.onload
will also wait for an SWF object to be loaded.If it doesn't wait for the SWF, then the effect would be that your
.patience
div will disappear too early, since the rest of the page will have finished loaded.It it does wait, but your div isn't disappearing at all, this suggests that you've simply got a trivial error somewhere in your real JS code that is preventing the
.hide()
from ever being called.Since you've said that the div isn't disappearing, I would suggest that you've got the latter problem, in which case a few minutes with a JS debugger should reveal (no pun intended) the problem.
可能是你的 jQuery 加载失败。另外,在使用 jQuery 时,请使用 jQuery 的 $.ready 而不是 window.onload,以确保在尝试执行任何操作之前一切都处于和平状态!
May be your jQuery failed to load. Also, when using jQuery, use jQuery's $.ready instead of window.onload to ensure all things are in peace before trying to do anything!
我的愚蠢错误!
我向您展示的代码没有任何问题,但我发现我正在调用
在头部,只有“js/jquery-1.6.js”。 1.min.js”脚本存在于我的服务器上。
现在感觉很愚蠢,但感谢所有做出贡献的人。
干杯
罗格
My stupid mistake!
Nothing wrong with the code I showed you but I discovered that I was calling
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
in the head and only the "js/jquery-1.6.1.min.js" script existed on my server.Feel stupid now but thanks all who contributed.
Cheers
Rog