你的
obj.onmouseover = function()
{
alert(i);
}
这种方法只有最后一个才有效果,需要改成这个样子的,
var li_o = document.getElementsByTagName("li");
for(var i=0;i
var obj = li_o[i];
if (obj.addEventListener) {
obj.addEventListener( "mouseover", cgbj, false );
}
else if (obj.attachEvent) {
obj.attachEvent( "onmouseover", cgbj );
}
}
function cgbj(e)
{
e = window.event || e;
var srcElement = e.srcElement || e.target;
srcElement.style.background="blue";
//鼠标经过变色
}
var lis = document.getElementsByTagName("li");
for(var i=0;i
lis[i].onmouseover = function() {
this.style.background="red";
alert(this.index) //上面改成title以后,这行相应改成his.title
}
lis[i].onmouseout = function() {
this.style.background="";
}
}
$("#cssmenu li").each(function () {
this.onmouseenter = function () {
this.style.background = 'rgb(51,51,51)';
};
this.onmouseleave = function () {
this.style.background = 'rgb(0,0,0)';
};
});