getElementsByClassName
getElementsByClassName
getElement sByclassName
不是什么浏览器都支持 getElementsByclassName 的
getElementsByclassName 得到的是一个数组
oBox.onmouseover ???
给数组指定鼠标事件?你这样写是不行的
<div id="WB_Blogger"> <div class="img" style="height:100px;width:100px;background-color:#00ff00;"> xxx </div> <div class="img" style="height:100px;width:100px;background-color:#c1c1c1;"> xxx </div></div><script type="text/javascript">window.onload = function() { var oBox = document.getElementsByClassName("img"); for (var i = 0, L = oBox.length; i < L; i++) { oBox[i].onmouseover = function() { this.className = "hover"; }; oBox[i].onmouseout = function() { this.className = ""; }; }};</script>
<div id="WB_Blogger"> <div class="img" style="height:100px;width:100px;background-color:#00ff00;"> xxx </div> <div class="img" style="height:100px;width:100px;background-color:#c1c1c1;"> xxx </div></div><script type="text/javascript">window.onload = function() { var oBox = document.getElementsByClassName("img"); for (var i = 0, L = oBox.length; i < L; i++) { oBox[i].onmouseover = function() { this.className = "hover"; }; oBox[i].onmouseout = function() { this.className = ""; }; }};</script>
貌似discuz对页面的js处理有问题。
最好使用 来引入。
把下面代码放入xxx.js
window.onload = function() { var oBox = document.getElementsByClassName("img"); for (var i = 0, L = oBox.length; i < L; i++) { oBox[i].onmouseover = function() { this.className = "hover"; }; oBox[i].onmouseout = function() { this.className = ""; }; }};