Jquery“隐藏加载”导致Javascript错误 [英] Jquery "hide on load" causing a Javascript error
问题描述
如果您需要完整的HTML,我会复制它,但它只包含一堆DIV,标题下的项目有一个子类
类。
我设法做了什么我需要通过:
$(document).ready(
$(。subitems)) .hide()
);
但是,在Chrome中,尽管它工作正常,但在控制台中出现以下错误: p>
无法复制格式化)
当我删除上面的代码时,错误会消失。我猜我做错了什么,但我看不到它,到目前为止,它在我测试过的每个浏览器中都能正常工作。
任何建议:
- 我做错了什么?
- 有没有更好的方法来实现我想要的?
你错过了匿名函数( {}
)包装,如下所示:
$(document).ready(function(){
$(。subitems)。hide();
});
它试图做 要注意的是,上面也有一个简短形式: I am trying to write a menu whose subitems vanish when the page is loaded. If you need full HTML, I will copy it, however it just consists of a bunch of DIVs, the items under the headers have a class of I have managed to do what I need via: However, in Chrome, despite it working fine, I get the following error in the console:
(Using picture as I can't copy the formatting well) When I remove the above code, the error goes. I guess I have done something wrong, but I can't see it and so far it works in every browser I have tested. Any suggestions on either:
You're missing the anonymous function( It's trying to do Just to note, there's a shorter form of the above as well:
这篇关于Jquery“隐藏加载”导致Javascript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! $(。subitems)。hide() .call()
在执行准备好的
处理程序时被覆盖......但这不是一个函数。相反,它立即执行(不在 document.ready
上),并在 document.ready $ c时抛出错误$ c>尝试运行
.hide()
的结果。
$(function(){
$( .subitems)。hide();
});
subitems
. $(document).ready(
$(".subitems").hide()
);
function() { }
) wrapper, like this:$(document).ready(function() {
$(".subitems").hide();
});
$(".subitems").hide().call()
under the covers when it executes the ready
handlers...but this isn't a function. Instead, it's executing immediately (not on document.ready
) and throwing an error when document.ready
tries to run the result of .hide()
.$(function() {
$(".subitems").hide();
});