Home  >  Q&A  >  body text

javascript - some questions about events

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<title>Title</title>
<style type="text/css">
    #ss{
        width:100px;
        height: 200px;
        background: rgba(0,32,34,1);
    }
</style>

</head>
<body>
<p id="aaa">

<img src="../下载.jpeg" alt="">
<script type="text/javascript">
    var oImg = document.querySelector("img");
    oImg.onload = function () {
        alert("123");
    }
    var oAA = document.querySelector("#aaa");
    oAA.onclick = function () {
        alert(this);
    }
</script>

</p>
<p id="ss" onclick="jj"></p>
<img src="../Download.jpeg" alt=" " onload="zzy" id="gg">
<script type="text/javascript">

var oLLLL = document.querySelector("#gg");
function jj() {
    alert(this);
}
console.log(oLLLL);
function zzy() {
    alert(oLLLL);
}

</script>
</body>
</html>

Could you please explain why the two functions in the second js cannot be triggered? I would be very grateful.
Another question is why the $(){} function in JQuery does not load as fast as the original js. Isn’t it possible to load js after the DOM tree is loaded? Why does it not have the original js

PHPzPHPz2704 days ago545

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-24 11:38:33

    1. The loading order of web pages is from top to bottom, so you see many people write js after the body, or at the very end inside the body. This is to ensure that p and other element tags are added before binding the event

    2. Why the framework is slower than the original code is because the framework’s comprehensive efficiency factor has done a lot of checks and judgments, so the performance is definitely not as fast as the original code.

    reply
    0
  • Cancelreply