jquery's data () function and HTML5 's Data property:
A new custom Data property is added to the HTML5, which allows you to add any property that begins with "data-", which is no longer displayed on the page, does not affect any of the original layout effects, and is read-write, such as:
<div id= "Thediv" data-webname= "Ant Tribe" > Ant Tribe Welcome </div>
The above code is a simple example of using a custom data property.
You can use the data () function of jquery to read these properties with the following code:
var webname= jQuery ("#thediv"). Data (' WebName '); Console.log (webname);
The above code can output custom attribute values: "Ant Tribe".
You can use JSON-formatted data in custom properties, such as:
<id= "Thediv" data-webaddress= ' {' address ': ' Shinan '} '> Ant Tribe welcome you </div>
You can also use the data () function of jquery and use the key of the JSON data to get the corresponding value, for example:
var address= $ ("#thediv"). Data (' WebName '). Address; Console.log (address);
More actions are not introduced here, specifically, you can refer to the data () method of jquery chapter.
Special Note:
In a non-HTML5 page or browser, you can still manipulate the "data-*" data using the. Data (obj) method.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8755
For more information, refer to: http://www.softwhy.com/jquery/
jquery's data () function and HTML5 's Data property