javascript - 除了特定图像之外的正文加载?
问题描述
我有一个包含大量文本和图像的 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>
这可能吗?如何?
解决方案
经过一番思考,我想出了一个简单的解决方法:
<!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>
推荐阅读
- flutter - 从 Stateful Widget 实例访问 State 成员
- c# - 我无法使用 try-catch 捕获 SqlException
- mongodb - 如何将两个不同查询的结果与猫鼬结合起来?
- html - 如何使这个框在 CSS 中居中对齐?
- android - Android - 未找到处理 HTTPS CustomTabsIntent 的活动
- spring - 使用证书文件 (.crt) 和私钥文件 (.key) 的 Spring Boot 应用程序中的 SSL
- android - 了解 Android 日志垃圾收集器
- image - Matlab中的稻谷分割
- javascript - 使用 splice react native 从数组中删除对象元素
- webpack - 如何捆绑将在“new Function()”中调用的脚本