<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<script type="text/javascript">
window.οnlοad=function(){
//1.获取元素
var box1 = document.querySelector("#box1");//等价于jquery var box1 = $("#box1")
var box2 = document.querySelector("header #box2");//等价于jquery var box1 = $("header #box2")
var box = document.querySelectorAll(".box"); //等价于jquery var box = $(".box")
//2.操作属性
var cls = box1.classList;//2.1获取元素所有
box1.classList.add("active");//2.2添加类名 等价于jquery box1.addClass("active");
box1.classList.remove("active");//2.3删除类名 等价于jquery box1.removeClass("active");
box1.classList.contains("active");//2.4类名是否存在 等价于jquery box1.hasClass("active");
//3.data 属性
var name = box1.dataset.name;//价于jquery box1.attr("data-name");
box1.dataset.age = "28";//价于jquery box1.attr("data-age","28");
}
</script>
<body>
<header>
<div id="box1" class="box" data-name="kiki">[box1]</div>
<div id="box2" class="box" data-name="tom">[box2]</div>
</header>
</body>
</html>