search

Home  >  Q&A  >  body text

javascript - Why does this code report an error?

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>满天飞舞的雪花</title>
</head>
<body bgcolor="#000000">
<script language="javascript">
    var num = 15; 
    x = new Array(); 
    y = new Array();
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;

    for (i = 0; i < num; i++) {
        x[i] = Math.random()*(doc_width-30)+10; 
        y[i] = Math.random()*doc_height;
        str = "<img src='../assets/img/coupon_ico.png' style='position:absolute;";
        str += "top:" + y[i] + ";left:" + x[i] + "'id='dot" + i + "'>";
        document.write(str);
    }
    function snow(){
        for (i = 0; i < num; i++){
            x[i]+=Math.random()*3;
            x[i]-=Math.random()*3;
            y[i]++;
            if(y[i]>doc_height)y[i] = -20;
            document.all["dot"+i].style.pixelTop = y[i];
            document.all["dot"+i].style.pixelLeft = x[i];
        }
        setTimeout("snow()",10);
    }
    snow();
</script>
</body>
</html>

ringa_leeringa_lee2862 days ago483

reply all(3)I'll reply

  • 黄舟

    黄舟2017-05-19 10:41:45

    The first TypeError is a code error in the installed browser plug-in. It has nothing to do with your code.

    The second 404 error is that there is no favicon icon. Look at the top of the browser tab to see if there is one to the left of the title. This is the small icon of a website. It doesn’t matter if you write a test demo by yourself. How to specifically add the keyword you search for is probably to put the image in the same level directory or the root directory, and use the link tag to introduce it in the page

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-19 10:41:45

    The error reported is to get the value from undefined.
    But the code you posted is not relevant.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:41:45

    What does 'able' mean?

    reply
    0
  • Cancelreply