作用:为前端开发者提供的自定义属性,在JavaScript中可以通过dataset来获取,不支持该属性的通过setAttribute或者getAttribute
data-user-list在js中获取时,”-“要改为驼峰式的写法,userList,这时候l是要大写为L
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="div1" data-user-list = "HELLO"></div>
<script type="text/javascript">
div1 = document.getElementById('div1');
alert(div1.dataset.userList);
div1.dataset.userList = 'YUMMY';
alert(div1.dataset.userList);
alert(div1.getAttribute("data-user-list"));
div1.setAttribute("data-user-list", "hello");
alert(div1.getAttribute("data-user-list"));
</script>
</body>
</html>