English 中文(简体)
设置 设置 设置 设置套用 DOM 属性不更新的周期性警报
原标题:setInterval alert does not update with dom attributes

当每隔5秒调用文件.body.scrollH8 的提醒时,提醒返回文档的最初滚动H8, 但即使页面的滚动高度明显改变, 也不会改变。 是否有方法可以让它返回页面的实际滚动高度, 而不仅仅是初始值?

代码/假码

<script>
    setInterval(function() {
        alert(document.body.scrollHeight);
    }, 5000);

    function extendHeight() {
    document.getElementById( box ).style.height = 1000;
    }
</script>

<body>
  <div id= box  style= height: 500px; >
    <button onClick="extendHeight();">Change Height</button>
  </div>
</body>

即使在单击按钮后,该提示还返回500 px。

最佳回答

问题是您应该将 1000px 指定给 document.getElementById( 框). stype.hileight 而不是 1000 :

<script>
    setInterval(function() {
        alert(document.body.scrollHeight);
    }, 5000);

    function extendHeight() {
    document.getElementById( box ).style.height = "1000px";
    }
</script>

<body>
  <div id= box  style= height: 500px; >
    <button onClick="extendHeight();">Change Height</button>
  </div>
</body>

小费:http://jsfiddle.net/kzLELr/" rel="nofollow">http://jsfididle.net/kzLELr/

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签