首页 > 解决方案 > 除了特定图像之外的正文加载?

问题描述

我有一个包含大量文本和图像的 HTML 页面。一个特定的图像加载速度很慢。我想在加载页面的所有其余部分时做一些事情,除了那个特定的图像。就像是:

<!DOCTYPE html>
<html>
  <head></head>
  <body onloadExceptSlowImage="doSomething();">
    ... several things, including some quick images ...
    <img id="SlowImage" src="slowImage.jpg" />
    ... several things, including some quick images ...
  </body>
</html>

这可能吗?如何?

标签: javascripthtmlonload

解决方案


经过一番思考,我想出了一个简单的解决方法:

<!DOCTYPE html>
<html>
  <head>
    <script>
      function doSomething() {
        // Do whatever
        document.getElementById("SlowImage").src="slowImage.jpg";
      }
    </script>
  </head>
  <body onload="doSomething();">
    ... several things, including some quick images ...
    <img id="SlowImage" src="tempImage.jpg" />
    ... several things, including some quick images ...
  </body>
</html>

推荐阅读