jQuery entry function, js entry function

Basic syntax: $(selector).action()

The dollar sign defines the jQuery
selector (selector) "query" and "find" HTML elements
jQuery's action() performs operations on the elements.
Examples:

$(this).hide() -Hide the current element

$("p").hide() -Hide all

element

$("p.test").hide() -Hide all class="test"

element

$("#test").hide() -Hide elements with id="test"

jQuery entry function:
All jQuery functions are located in a document ready function:

$(document).ready(function(){
 
   // 开始写 jQuery 代码...
 
});

Tip: Concise writing (the same effect as above):

$(function(){
 
   // 开始写 jQuery 代码...
 
});

JavaScript entry function:

window.onload = function () {
    // 执行代码
}

The difference between jQuery entry function and JavaScript entry function:

 jQuery 的入口函数是在 html 所有标签(DOM)都加载之后,就会去执行。
 JavaScript 的 window.onload 事件是等到所有内容,包括外部图片之类的文件加载完后,才会执行。

Insert picture description here
Reference rookie Tutorial

Guess you like

Origin blog.csdn.net/qq_34462698/article/details/112763607