需要Javascript对象(IE8)

时间:2013-05-29 11:20:18

标签: javascript object internet-explorer-8 required

javascript for elements re-size在我的tumblr主题上运行正常,但我在IE8中的以下行中得到了对象所需的错误:

fschildren = $("fs_wrapper").childNodes;

感谢您的帮助 彼得

<script type="text/javascript">

function resizedivs() {

$ = function(id) { return document.getElementById(id); }

fschildren = $("fs_wrapper").childNodes;
postc = 0;
thedivs = new Array();

for(i = 0; i < fschildren.length; i++) {
    if(fschildren[i].tagName == "DIV") {
        thedivs[postc] = fschildren[i];
        postc++;
    }
}

newwidth = 0;
for(i = 0; i < thedivs.length; i++) {
    if(newwidth <= document.body.clientWidth) {
        newwidth = newwidth + (thedivs[i].clientWidth)+15;
    }

    if(newwidth >= document.body.clientWidth || newwidth >= 1300) { // 100 for padding minus 15 extra
        newwidth = newwidth - (thedivs[i].clientWidth+15);
        break;
    }
}

$("fs_wrapper").style.width = newwidth-0+"px";
$("fs_wrapper").style.position = "relative";
$("fs_wrapper").style.left = "0px";

$("sec2").style.width = newwidth-0+"px";
$("sec2").style.position = "relative";
$("sec2").style.left = "0px";

$("sec3").style.width = newwidth-0+"px";
$("sec3").style.position = "relative";
$("sec3").style.left = "0px";

}

window.onresize = function() {
    resizedivs();

}

window.onload = function() {
    resizedivs();
}
</script>

1 个答案:

答案 0 :(得分:1)

对象真的存在吗?

myObj = document.getElementById('myObj');
if(!myObj) {
  alert("4004 not found");
  return;
}

您缺少正确的选择器.用于课程,或#用于ID

请参阅此http://www.w3schools.com/jquery/jquery_ref_selectors.asp