How to use H5 DataSet

Xiaobian to share with how to use the H5 Dataset, I believe that most people don’t know much, so share this article to everyone, I hope everyone has a big gain after reading this article, let us let us Let’s take a look!

The HTML5 standard allows you to embed the properties similar to Data- * in a normal element tag to implement some simple data access. Its quantity is not restricted, and can also be dynamically modified by JavaScript, and also supports the CSS selector for style settings. This makes the data attributes especially flexibly and is very powerful. With such an attribute we can make more ordered and intuitive data presets or storage. Of course, any of the label elements can be casually coupled with any custom properties, or they can get their values, but there is no flexibility. Let’s take a look at the free attribute storage data.

Examples of SetAttribute and GetAttribute

                var mdoc = document.getlementByid ('Music'); Alert (MDOC      
Operates this code, and the value corresponding to the Mtitle can be obtained on the page. Although you can write, but you want to preset more information, a semantic properties DATA- *. For example, just now, I want to introduce more about this song data, which can be written in this song:

latch (feat. Sam smith)
   Access attributes can also be used in the first way: var album = document.getlementByid ("Music-latch"). GetAttribute ("Data-Album");  Console.log (album);  
But this method is relatively low, if you encounter multiple Data- * custom fields, you want to get all the DATA properties and package it into an object, Must be a loop, very troublesome. But we have a DataSet API available. 2. Access DataSet

with DataSet API to access all Data fields of the elements more convenient to access all Data fields, easy access and traversal in the way. For example, for the above example, it can be operated:

VAR MDOC = Document.GtelementByid (‘music-latch’); var DS = mdoc.dataset; alert (DS.DATE + ‘-‘ + DS.ALBUM);

At this time, when we visited DATA, there is no need to “Data-” keywords, direct use .dataset.name can be accessed. This is more convenient than above. Any changes made are available in real time to the elements Data properties.

How do you use all the contents of the Dataset of H5, thank you for reading! I believe everyone has a certain understanding, I hope to share the content of everyone, if you want to learn more knowledge, please pay attention to Tumi Yun Industry News Channel!
                    
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment