jQuery event operation

What is the difference between $( function(){} ); and window.onload = function(){}?

When are they triggered respectively?
1. After the jQuery page is loaded, the browser's kernel will execute it immediately after the DOM object is created after parsing the tags of the page.
2. After the native js page is loaded, in addition to waiting for the browser kernel to parse the tag to create a DOM object, it also needs to wait for the content to be loaded when the tag is displayed
.
What order do they trigger?
1. After the jQuery page is loaded, execute it first.
2. After the native js page is loaded,
how many times do they execute?
1. After the native js page is loaded, only the last assignment function will be executed.
2. After the jQuery page is loaded, all the registered function functions are executed in order.

Other event handling methods in jQuery:

Click()
can bind the click event, and trigger the click event
mouseover()
mouse move in event
mouseout()
mouse move out event
bind()
can bind one or more events to the element at a time.
The
use of one() is the same as bind. But the event bound to the one method will only respond once.
unbind()
is the opposite of the bind method . Unbind events
live()
is also used to bind events. It can be used to bind the events of all elements matched by the selector. Even if this element is dynamically created out behind
them are also effective

    <script type="text/javascript">
      $(function () {
     
     
      
        //单击事件

        $("h5").click(function () {
     
     
          //传function是绑定事件
          // alert("你点击了");
        });
        //单击事件
        $("button").click(function () {
     
     
          //不传function是触发事件
          $("h5").click();
        });
        // 鼠标移入事件
        $("h5").mouseover(function () {
     
     
          console.log("你进来了");
        });
        //鼠标移出事件
        $("h5").mouseout(function () {
     
     
          console.log("你出去了");
        });
        //跟 bind 方法相反的操作,解除事件的绑定
        $("button").unbind("click");
        // 可以给元素一次性绑定一个或多个事件。
        $(".head").bind("click  mouseout", function (event) {
     
     
          if (event.type == "click") {
     
     
            $("<div>我被点击了</div>").appendTo(".head");
          } else {
     
     
            $("<span>我出去了</span>").appendTo(".head :last");
          }
        });

        //1.通常绑定事件的方式
        //2.jQuery提供的绑定方式:bind()函数
        //3.合并“鼠标移入”和“鼠标移出”事件
        //4.合并单击事件
        //5.切换元素可见状态
        //6.只绑定一次
      });
    </script>

Go to jQuery practice

Guess you like

Origin blog.csdn.net/qq_44788518/article/details/108248866