你的this没有引用
这样
var temp=event.srcElement;
temp.bgColor='#DDDDDD'
temp.borderColor='#FF8A21';
temp.style.color='#000000';其实这样就可以
onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e6ebf7'" onmouseout="this.style.backgroundColor=currentcolor"
这样
var temp=event.srcElement;
temp.bgColor='#DDDDDD'
temp.borderColor='#FF8A21';
temp.style.color='#000000';其实这样就可以
onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e6ebf7'" onmouseout="this.style.backgroundColor=currentcolor"
能帮我看看这为什么不对吗?
function XX(){
var temp=event.srcElement;
temp.bgColor='blue'
temp.borderColor='red';
temp.style.color='black';
}
<tr bgcolor="#DDDDDD" onmouseover="XX();">
<td>ABCDEFG</td>
</tr>
<tr>
alert(obj.onmouseover)里可以看到的this才能指代当前的对象.
改成如下就行:<script language="javascript">
function XX(){
this.bgColor='#FF8A21';
this.borderColor='';
this.style.color='#FFFFFF';
this.style.cursor='hand';
}
function ZZ(){
this.bgColor='#DDDDDD'
this.borderColor='#FF8A21';
this.style.color='#000000';}</script>
<tr id=aaa bgcolor="#DDDDDD" onmouseover="XX();" onmouseout="ZZ();";>
<td>ABCDEFG</td>
</tr>
<script>
var tempTd=document.getElementById("aaa");
tempTd.onmouseover=XX;
tempTd.onmouseout=ZZ;
</script>
改变td的背景:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title>
<script>
function changeTdStyle(event,heightLight){
var obj= event.srcElement||event.target;
if(obj.tagName=="TD"){
if(heightLight){
obj.style.backgroundColor='#8888ff';
}
else{
obj.style.backgroundColor='';
}
}
}
</script>
</head><body >
鼠标移动,改变td背景:
<br>
<table border="1" width="400" height="200" bgcolor="#cccccc"
onmouseover="changeTdStyle(event,true);"
onmouseout="changeTdStyle(event,false);" >
<tr>
<td>甲</td>
<td>乙</td>
<td>丙</td>
<td>丁</td>
</tr>
<tr>
<td>子</td>
<td>丑</td>
<td>寅</td>
<td>卯</td>
</tr>
<tr>
<td>上</td>
<td>大</td>
<td>人</td>
<td>孔</td>
</tr>
<tr>
<td>天</td>
<td>地</td>
<td>玄</td>
<td>黄</td>
</tr>
<tr>
<td>公</td>
<td>侯</td>
<td>伯</td>
<td>子</td>
</tr>
<tr>
<td>孟</td>
<td>仲</td>
<td>叔</td>
<td>季</td>
</tr>
</table>
</body></html>
function XX(t){
t.style.backgroundColor='#FF8A21';
t.style.borderColor='';
t.style.color='#FFFFFF';
t.style.cursor='hand';
}
function ZZ(t){
t.style.backgroundColor='#DDDDDD'
t.style.borderColor='#FF8A21';
t.style.color='#000000';}
</script><tr bgcolor="#DDDDDD" onmouseover="XX(this);" onmouseout="ZZ(this);">
<td>ABCDEFG</td>
</tr>