Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery objects are converted to js objects

Shulou Source: shulou.com Published: 2022-06-02 15:41:02 09月27日 Update

This article mainly introduces "how to convert jquery objects into js objects". In daily operation, I believe many people have doubts about how to convert jquery objects into js objects. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about how jquery objects are converted into js objects. Next, please follow the editor to study!

The method of converting jquery object into js object: 1, using "jquery object [index]" statement for conversion; 2, using "jquery object .get (index)" statement for conversion.

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

Objects of type js and objects of type jquery are two completely different objects. However, the methods of the two objects cannot be called to each other. So what if the js object wants to call a method in jquery, or the jquery object wants to call a method in js? This involves the conversion between js objects and jquery objects.

For example:

① document.getElementById ("text") .hide

Cannot be implemented, because hide () is a method of the jquery object, and the js object cannot be called.

② $("# text2") [xss_clean] = "jredu"

It is also impossible to implement, because innerHTML is a property of the js object, and the jquery object cannot be used.

So, let's show you how to convert js to jQuery:

-convert 1:jquery objects to js objects

-convert 2:js objects to jquery objects

Convert jquery objects to js objects

There are two ways to convert a jQuery object into a js object: [index] and .get (index)

(1) the jQuery object is a data object, and the corresponding js object can be obtained by [index] method.

Such as:

Var $vault $("# v"); / / jQuery object var vault roomv [0]; / / js object alert (v.checked) / / detect whether the checkbox is selected

(2) provided by jQuery itself, the corresponding js object is obtained by .get (index) method.

For example: var $vault $("# v"); / / jQuery object var v=$v.get (0); / / js object alert (v.checked) / / detect whether the checkbox is selected

Convert js objects to jquery objects

If you are already a js object, you only need to wrap the DOM object with $() to get a jQuery object.

Syntax: $(js object)

Such as:

Var v=document.getElementById ("v"); / / js object var $vault $(v); / / jQuery object

After the conversion, you can use the jQuery method at will.

At this point, the study on "how to convert jquery objects into js objects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Objects methods learning next methods more types statements problems help detection different practical between can pass properties what to do tutorials data articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info MariaDB Shulou Information Huawei