JavaScript-test jQuery and javascriptjquery
Test the JavaScript Framework library-jQuery
Reference jQuery
To test the JavaScript library, you must reference it on the webpage.
To reference a library, use the <script> tag. Set the src attribute to the library URL:
Reference jQuery
<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>
JQuery description
The main jQuery function is the $ () function (jQuery function ). If you pass a DOM object to this function, it returns the jQuery object with the jQuery function added to it.
JQuery allows you to use the CSS selector to select elements.
In JavaScript, you can assign a function to handle window loading events:
JavaScript:
Function myFunction ()
{
Var obj = document. getElementById ("h01 ");
Obj. innerHTML = "Hello jQuery ";
}
Onload = myFunction;
The equivalent jQuery is different:
JQuery:
Function myFunction ()
{
$ ("# H01" ).html ("Hello jQuery ");
}
$ (Document). ready (myFunction );
In the last line of the code above, the html dom document Object is passed to jQuery: $ (document ).
When you pass a DOM object to jQuery, jQuery returns the jQuery object packaged with an html dom object.
The jQuery function returns a new jQuery object, where ready () is a method.
Since a function is a variable in JavaScript, you can pass myFunction as a variable to jQuery's ready method.
|
JQuery returns the jQuery object, which is different from the passed DOM object. The attributes and methods of a jQuery object are different from those of a DOM object. You cannot use html dom attributes and methods on jQuery objects. |
Test jQuery
Please try the following example:
Instance
<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>
<Script>
Function myFunction ()
{
$ ("# H01" ).html ("Hello jQuery ")
}
$ (Document). ready (myFunction );
</Script>
Please try this example again:
Instance
<Script src = "https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</Script>
<Script>
Function myFunction ()
{
$ ("# H01"). attr ("style", "color: red" ).html ("Hello jQuery ")
}
$ (Document). ready (myFunction );
</Script>