0

除非我将它们放在另一个函数中并使用 html 输入执行它们,否则此 js 代码的最后一行不会执行。

function baseSize() {
    var available = window.screen.availHeight;

    var windowHeight = window.screen.height;
    var makeHeight = 849 - windowHeight;
    document.body.style.backgroundPosition = "0px -" + makeHeight + "px";

    var container = document.getElementById("container");
    container.style.height = available + "px";

    var right = document.getElementById("right");
    right.style.height = available - 230 + "px";

    var left = document.getElementById("left");
    left.style.height = available - 230 + "px";

    var storyright = document.getElementById("storyright");
    storyright.style.height = available - 40 + "px";
}

为什么会这样,我该如何解决/解决它?(而且我知道它可能很混乱,所以不要建议收紧它的方法。我稍后会谈到。)

这是html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<link rel="stylesheet" type="text/css" href="stories.css" />
<script type = "text/javascript" src="script.js">
</script>
    <div id = "container">
    <body onLoad = "baseSize(); storySize();">
    <div id = "head">
        <table class="links">
        <tr>
        <td class="link"><a href="index.html">Home</a></td>
        <td class="link"><a href="poetry.html">Poetry</a></td>
        <td class="link"><a href="essays.html">Essays</a></td>
        <td class="link"><a href="stories.html">Stories</a></td>
        <td class="about"><a href="about.html">About</a></td>
        </tr>
        </table>
        <div id = "icon"><p>Craig InTheDell</p></div>
    </div>
    <div id="container2">
    <div id="top">
        <table>
        <tr>
        <td class="button"><input type="image" src="mostrecentbutton.jpg" onClick="showContent1()"/></td>
        <td class="button"></td>
        <td class="button"></td>
        <td></td>
        </tr>
        </table>

    </div>
    <div id="storyright">
        <div id="content1">
        <input type = "button" Value = "click me!" onClick = "storySize()"/>
        </div>
    </div>
    </div>
    </body>
    </div>
</html>
4

1 回答 1

1

如果var left没有styleorstyle.height属性,它可能会在那里杀死 javascript。查看您的控制台 - 出现任何错误?

于 2013-07-08T23:26:53.087 回答