Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How jquery objects are converted to js objects

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report