1

javascript for elements re-size 在我的 tumblr 主题上运行良好,但在 IE8 的以下行中出现 object required 错误:

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>
4

1 回答 1

1

对象真的存在吗?

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

您缺少正确.的类或#id选择器

看到这个http://www.w3schools.com/jquery/jquery_ref_selectors.asp

于 2013-05-29T11:22:46.727 回答