I used to think that I could only use jquery's data() to get
Haha I'm too weak
<!DOCTYPE html> <html> <head> <title>dataset</title> <meta charset="utf-8"> </head> <body> <div id='div' data-index='demo'> </div> </body> <script type="text/javascript"> var a = ('div'); (a) ()//demo </script> </html>
You can get the data attributes of the DOM element by directly using dataset
OK, you can also use js to getAttribute()
('data-index') ==>"demo"
The above article js to obtain the data attribute implementation method of html5 is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.