經過 data-xx
在標籤中設置的屬性可用 dataset.xx
獲取html
例如spa
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div class="a" data-name='myName'> A </div> </body> <script> var a = document.querySelector('.a') var n = a.dataset.name console.log(n) </script> </html>