|
藍森林 http://www.lslnet.com 2006年8月25日 8:28
求教如何用js控制css的值
<tr onmuseover="javascript:changecolor()"><td width="180" height="12" ><a href="Player.Asp" target="_blank"> 歌曲*** </a></td></tr>
請教該如何些這個changecolor(),用它來控制css,css可以控制tr的backgroundColor,鏈接文字的color,鏈接的text-decoration |
頁面上這麼搞一下
<tr id="test" onmuseover="javascript:changecolor(this.id)"><td width="180" height="12" ><a href="Player.Asp" target="_blank"> 歌曲*** </a></td></tr>
然後寫一個方法
function changecolor(id){
var tempEl = window.document.getElementById(id);
tempEl.style.backgroundColor = "#ff0000";
tempEl.children[0].children[0].style.color = "";
tempEl.children[0].children[0].style.textDecoration = "";
}
沒做過測試,鏈接的顏色和樣式恐怕有問題。
|
實現不了,不知道哪裡的問題.看了看資料,找不出毛病來,怎麼就不能實現呢? : ( |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT>
function changecolor(id){
var tempEl = window.document.getElementById(id);
tempEl.style.backgroundColor = "#ff0000";
tempEl.children[0].children[0].style.color = "#00ff00";
tempEl.children[0].children[0].style.textDecoration = "none";
}
</SCRIPT>
</head>
<body>
<TABLE>
<tr id="test" onmouseover="javascript:changecolor(this.id)">
<td width="180" height="12" ><a href="Player.Asp" target="_blank"> 歌曲*** </a></td></tr>
</TABLE>
</body>
</html> |
哎 第一次回答人家問題 就好人做到底了 回去調了調 沒問題 |
謝謝,可以了. |
|