1、获取id的对象
2、需要获取的就是data-id 和 dtat-vice-id的值
一:getAttribute()方法
const getId = document.getElementById('getId'); // //getAttribute()取值属性 console.log(getId.getAttribute("data-id"));//122 console.log(getId.getAttribute("data-vice-id"));//11 // //setAttribute()赋值属性 getId.setAttribute("data-id","48"); console.log(getId.getAttribute("data-id"));//48
二:dataset()方法
//data-前缀属性可以在JS中通过dataset取值,更加方便 console.log(getId.dataset.id);//112 //data-