得到当前元素并改变背景色:
<script type="text/javascript">
function changeColor(src){
var obj=document.getElementsByTagName("td");
for (i=0;i<obj.length;i++ )
{
obj[i].style.backgroundColor="white";
}
src.style.backgroundColor="red";
src.children.tags('a')[0].style.backgroundColor="cyan";
alert(src.parentElement.tagName);
}
</script>
<table>
<tr>
<td onclick="javascript:changeColor(this)"><a>aaa</a></td>
<td onclick="javascirpt:changeColor(this)"><a>bbb</a></td>
<td onclick="javascirpt:changeColor(this)"><a>ccc</a></td>
</tr>
</table>
注:改变背景图片
obj[i].style.background="url(
http://localhost:8080/images/abcimg.gif)";