日期:2014-05-16 浏览次数:20469 次
js动态添加classname
?今天无疑在qq拍拍源码上看到一串这样的代码可以动态添加classname觉得不错就抄了下来
<script type="text/javascript">
window.onload = function () {
var ulBox = document.getElementById("content");
var list = ulBox.getElementsByTagName("li");
for (var i=0; i<list.length; i++) {
list[i].onmouseover=function() {
this.className="hover";
}
list[i].onmouseout=function() {
this.className="";
}
}
}
</script>
?