赞
踩
- <div class="box"></div>
- <script>
- let box=document.querySelector('.box')
- box.setAttribute('data-ID',10)
- console.log(box.getAttribute('data-ID'))
- </script>
对象名.dataset
- <div class="box" data-name="刘德华" data-age="18"></div>
- <script>
- let box = document.querySelector('.box')
- box.setAttribute('data-ID', 10)
- console.log(box.getAttribute('data-ID'))
-
- // 获取全部自定义属性dataset
- console.log(box.dataset)
- //获取单个自定义属性
- console.log(box.dataset.name)
- </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。