<div onclick="clickD(this)">点我试试</div>
<div onmouseover="overD(this)" onmouseout="outD(this)">鼠标移动试试</div>
function clickD(obj){
alert(obj.innerHTML);
}
function overD(obj){
obj.style.color="#f00";
obj.style.fontSize="18px";
}
function outD(obj){
obj.style.color="#000";
obj.style.fontSize="12px";
}
document.write("aaa<br>");
document.write("bbb<br>");
document.write("ccc<br>");
with(document){
write("aaa<br>");
write("bbb<br>");
write("ccc<br>");
}
注意:
(1).div中this表示div这个对象
(2).在css中是font-size,在js中是fontSize
(3).有多个重复根的代码时,可以使用with(){},括号里面是根元素