除非我将它们放在另一个函数中并使用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>
答案 0 :(得分:1)
如果var left
没有style
或style.height
属性,则可能会在那里终止javascript。看看你的控制台 - 出现任何错误?