Learning JQuery: jquery js objects and objects distinguish and conversion

JQuery and JS difference between the object and the object conversion

  1, JQuery object when the operation more convenient

  2, JQuery objects and methods are not common objects js

  3, both the conversion

    * Jq -> js: jq Object [Index] jq or objects .ge (index)

    * Js -> jq: $ (js objects)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>jquery和js对象的转换</title>

    <script src="js/jquery-3.3.1.js"></script>
</head> 
< Body > 

    < div ID = "DIV1" > DIV1 ..... </ div > 
    < div ID = "Div2" > Div2 ..... </ div > 
    
    < Script > 
        // 1. By way js div called to get the name of all the html element objects 
        var divs = document.getElementsByTagName ( " div " ); 
        Alert (divs.length);     // can use it as an array 
        // of divs all div tags so that the body content becomes "aaa"
        for ( were in =  0 ; in< Divs.length; I ++ ) {
             // divs [I] .innerHTML = "AAA"; 
            $ (divs [I]) HTML (. " CCC " );      // JS -> JQ 
        } 

        // 2, div called to get the name of all the html element objects by jq way 
        var $ divs = $ ( " div " ); 
        Alert ($ divs.length);    // can also be used as an array to use 
        // to make divs all div content tag body becomes "bbb", the use mode jq 
        // $ divs.html ( "BBB"); 
        $ divs [ 0 ] .innerHTML =  " ddd " ;     // JQ objects (index)
        divs.get $ ( . 1 ) .innerHTML =  " Eee " ;      // JQ objects .get (index) 

        / * 
            . 1, JQ object when the operation is more convenient 
            2, jq js objects and methods are not common objects 
            3, both the conversion 
                * jq -> js: jq object (index) or the object jq .get (index) 
                * JS -> jq: $ (JS objects) 
        * / 

    </ Script > 


</ body > 
</ HTML >

 

Guess you like

Origin www.cnblogs.com/flypig666/p/11607280.html