<div id="div1">这是个测试</div>
<p class="acc"></p>
<p class="dd"></p>
//js DOM的几个常用方法
//document.getElementById,
// document.getElementsByTagName,
// document.getElementsByClassName,
// getAttribute,
// setAttribute var div1 = document.getElementById("div1").innerHTML;
console.log(div1);//output:这是个测试 var pars = document.getElementsByTagName("p");
for (var i = ; i < pars.length; i++) {
var title = pars[i].getAttribute("class");
if (title) {
pars[i].setAttribute("class", "look");//修改class的值为look
console.log(pars[i].getAttribute("class"));//output:look
}
} var cls = document.getElementsByClassName("look");
for (i in cls) {
console.log(cls[i].innerHTML);//111,222
}