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 to use the data function in jquery

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of "how to use the data function in jquery". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to use the data function in jquery" can help you solve the problem.

In jquery, data means "data". The data () function is used to access data on the specified element and return the set value. the data accessed through this function is temporary data, and the data stored after the page is refreshed will be removed with the syntax of "$.data (element,key,value)".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

What is the meaning of data in jquery

The $.data () function is used to access data on the specified element and returns the set value.

Hint: 1. This is an underlying method, and the .data () method is more convenient to use.

two。 The data accessed through the data () function is temporary data, and once the page is refreshed, the previously stored data will be removed.

3. This method currently does not provide cross-platform settings on XML documents, and Internet Explorer does not allow data to be attached through custom properties in XML documents.

Grammar

Usage one

$.data (element, key, value)

Note: 1. The data accessed through the data () function is temporary data, and once the page is refreshed, the previously stored data will be removed.

2. Undefined is an unrecognized data value. Calling jQuery.data (el, "name", undefined) returns the corresponding "name" data, which is equivalent to jQuery.data (el, "name").

We can set different values on an element and get these values:

JQuery.data (document.body, 'foo', 52); jQuery.data (document.body,' bar', 'test')

Usage two

$.data (element, key)

We can set different values on an element and get these values:

Alert (jQuery.data (document.body, 'foo')); alert (jQuery.data (document.body))

Parameter description

Element Element type DOM object to store data

Key is optional. The key name string specified by the String type.

Value is optional. Any type of data that the Object type needs to store.

This is the end of the content about "how to use the data function in jquery". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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