jquery is a good JAVASCRĪPT framework, $ is the jquery library statement, it is very unstable (I often met), change a stable writing jquery.noconflict (); JQuery (document). Ready (function () {});
The advantage of using jquery is that it wraps the operation of various browser versions of Dom objects (JavaScript DOM objects you should know, that's it).
Like jquery:
$ ("div p"); (1)
$ ("Div.container"); (2)
$ ("div #msg"); (3)
$ ("Table A", context); (4)
$ ("#myId"); (5)
The first line of code gets the <p> element under all <div> tags. The second line of code gets the <div> element with class container, and the third line gets the element with the ID msg below the <div> tag. The four lines of code get all the connection elements in the table with context. Line five gets all the elements with ID myID
If you are familiar with CSS, you will find these wording familiar! That's right. Is. See the mystery. jquery is the way to find elements within a DOM object. Similar to the CSS selector.
Now, answer your specific questions.
$ (document). Ready (function () {
Alert ("Hello");
});(1)
<body onload= "alert (' Hello ');" > (2)
The above two pieces of code are equivalent. But the benefit of code 1 is to do performance and logical separation. And you can do the same thing in different JS files, that is $ (document). Ready (FN) can appear repeatedly on one page without conflict. Basically, many of jquery's plugin take advantage of this feature, and because of this feature, multiple plugin are used together and there is no conflict during initialization.
If we are
$ (document). Ready (function () {
What to add
});
Add content $ (". Btn-slide"). Click (function () {
Alert ("You clicked the class equals Btn-slide connection" in the A tag);
});
Indicates that when we click on Class=btn-slide's Super Connection, "you clicked the connection with class equals btn-slide in Tab A" dialog box.
So easy to use, so using jquery is a good choice.