1--Jquery object and JS object

Jquery object

The JQuery object is the object produced after the DOM object wrapped by JQuery.
The JQuery object is unique to JQuery. If an object is a JQuery object, you can use the methods in JQuery. The attributes and methods in the previous DOM object cannot be used in JQuery, and the attributes and methods in the JQuery object cannot be used in the original JS.
Example 1:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Jquery对象和JS对象</title>
    <script src="jquery-1.11.3.js"></script>
</head>
<body>
    username:<input id="username" value="admin"><br>
    <script>
        /*使用原生态的js获取一个DOM对象*/
       var e_input= document.getElementById("username");
        /*使用原生态的js通过DOM属性获取了value的值*/
        /*var val=e_input.value;*/
        /*错误: DOM对象不能使用JQuery中的属性和方法*/
        var val=e_input.val();
        alert(val);
    </script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Jquery对象和JS对象</title>

    <script src="jquery-1.11.3.js"></script>
</head>
<body>
    username:<input id="username" value="admin"><br>
    <script>
        /*通过JQuery获取一个元素节点(JQuery对象)*/
      var e_input=  $("#username");
     /* var val=  e_input.value;*/
     /*错误: Jquery对象不能使用JS中的属性*/
      var val=  e_input.val();
        alert(val);
    </script>
</body>
</html>

Summary:
Although the JQuery object is a encapsulation of the original JS.
The properties and methods in JS can only be used in JS.
The properties and methods in the JQuery object can only be used in JQuery.

Guess you like

Origin blog.csdn.net/qwy715229258163/article/details/113848083