jQuery/Javascript 无法访问有关元素的信息
我的 DOM 似乎有问题,元素的样式全部显示为空白。
我的 jQuery 在页面加载时根本
// JavaScript Document
$(document).ready(function(){
$(#mainContent).css("min-height", function(){
return $(window).height() + 'px';
});
});
没有任何反应。
我怀疑语法没有问题,或者如果有的话,这不是导致我的问题的原因。我尝试自己用 javascript 编写脚本,它产生了类似的结果,这就是我首先转向 jQuery 的原因。
如果我
alert("text")
工作正常,但如果我尝试,
$(#mainContent).css("min-height")
那么什么也不会发生。
我在一个单独的javascript文件中创建了一个简单的变量
var mainCon = document.getElementById("mainContent");
并使用firebug,在声明变量后放置一个断点,然后当使用firebug检查变量时,样式中的所有内容都是空白的,例如
height ""
width ""
color ""
等等。
我完全不知道是什么导致了这个问题,我为此失眠了,我已经从谷歌中搜寻出来,似乎找不到任何相关的东西。
您能找到的任何帮助将不胜感激, 提前致谢
There seems to be a problem with my DOM, in that the style of elements are all appearing blank.
My jQuery is simply
// JavaScript Document
$(document).ready(function(){
$(#mainContent).css("min-height", function(){
return $(window).height() + 'px';
});
});
Nothing happens on page load.
I suspect there is not a problem with the syntax, or if there is, this is not what is causing my problem. I have tried to script this myself in javascript and it yielded similar results which is why I turned to jQuery in the first place.
if I
alert("text")
it works fine but if I try
$(#mainContent).css("min-height")
then nothing happens.
I have, in a separate javascript file created a variable which is simply
var mainCon = document.getElementById("mainContent");
and using firebug, put a breakpoint in after the variable is declared, then when inspecting the variable using firebug, everything within styles is blank, eg
height ""
width ""
color ""
etc.
I have absolutely no idea what is causing this problem and I am losing sleep over it, I have scraped the hell out of google and can't seem to find anything relevant.
Any help you can find will be massively appreciated,
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要引用您的选择器(特别是
#mainContent
):You need to quote your selectors (specifically
#mainContent
):您在选择器中缺少引号:
you are missing quotes in the selector: