这是你如何整合Onload事件? [英] Is this how you incorporate an Onload Event?

查看:122
本文介绍了这是你如何整合Onload事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题。我想在HTML5中加入一个onload事件。这是我的代码,但它拒绝工作。请告诉我我的错误。

I have a quick question. I am trying to incorporate an onload event in HTML5. Here is my code but it refuses to work. Please let me know what I am doing wrong.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Animation</title>

    <script>
        document.getElementById('videoBackground').onload = function()
        {
            document.body.style.backgroundColor = 'black';
        }
    </script>

    <script type="text/javascript" src="js/animCD.js"></script>    
    <link rel="stylesheet" href="style.css" type="text/css" />

    </head>
    <body>

    <video id="videoBackground" poster="img/loading.png" onload="function()" width="1920" height="1080" preload="auto" onprogress="animCD_onprogress();" onended="animCD_start();">
        <source id="colorVid_mp4" type="video/mp4" src="img/luther_color.mp4">      
    </video>


推荐答案

执行 getElementById('videoBackground') id videoBackground 的元素尚不存在。

At the point where you are executing getElementById('videoBackground') the element with the id videoBackground doesn't exist yet.

在您创建 videoBackground 元素的位置下移动脚本,或者在使用 document.onload

Either move the script below where you created the videoBackground element or run the script after the DOM loads using document.onload.

这篇关于这是你如何整合Onload事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆