点击表格,变某一栏的底色。有点急,需要多少分都可以。

waynege 2003-08-18 10:15:27
从数据库中取出后建立的表格,行数不定。
功能:鼠标点击某一行,该行变底色;
鼠标点击另一行,则新的行变色,原先的那行需恢复默认的底色。

当前已用onmousedown实现了变色,但是点击新的行后,不知道该如何将原先的那行恢复到默认的底色,即第2次点击时,页面出现2行已变色的。

...全文
49 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuzxit 2003-08-18
  • 打赏
  • 举报
回复
sorry

function selectIng(){
var newTr=event.srcElement;
while(newTr.tagName != "TR")newTr=newTr.parentElement;
newTr.style.backgroundColor=IngColor;
if(olrTr != null)oldTr.style.backgroundColor=EdColor;
oldTr=newTr;
}

-->

function selectIng(){
if(olrTr != null)oldTr.style.backgroundColor=EdColor;
EdColor=newTr.style.backgroundColor
var newTr=event.srcElement;
while(newTr.tagName != "TR")newTr=newTr.parentElement;
newTr.style.backgroundColor=IngColor;
oldTr=newTr;
}
liuzxit 2003-08-18
  • 打赏
  • 举报
回复
<body>
<table border=1 id=t1>
<tr onmouseover="selectIng()" onmouseout="selectEd()"><td>a</td><td>b</td></tr>
<tr onmouseover="selectIng()" onmouseout="selectEd()"><td>c</td><td>d</td></tr>
</table>
<script>
var EdColor,IngColor="#dddddd",olrTr;
function selectIng(){
var newTr=event.srcElement;
while(newTr.tagName != "TR")newTr=newTr.parentElement;
newTr.style.backgroundColor=IngColor;
if(olrTr != null)oldTr.style.backgroundColor=EdColor;
oldTr=newTr;
}

function selectEd(){
var newTr=event.srcElement;
while(newTr.tagName != "TR")newTr=newTr.parentElement;
newTr.style.backgroundColor=EdColor;
olrTr = null;
}
</script>
</body>
Brookes 2003-08-18
  • 打赏
  • 举报
回复
<tr onmouseover=javascript:this.bgColor='#e9f2f5' onmouseout=javascript:this.bgColor='#FFFFFF'><td width=46%></td><td.....></tr>
kingdomzhf 2003-08-18
  • 打赏
  • 举报
回复
<body>
<table border=1 id=t1>
<tr onmouseover="selectRow(this)"><td>a</td><td>b</td></tr>
<tr onmouseover="selectRow(this)"><td>c</td><td>d</td></tr>
</table>
<script>
function selectRow(oCurrent)
{
oCurrent.style.backgroundColor="red";

for(var i = 0; i < document.all('t1').rows.length;i++)
{

if(t1.rows[i] != oCurrent) t1.rows[i].style.backgroundColor="ffffff";
}
}
</script>
</body>
ky99xing 2003-08-18
  • 打赏
  • 举报
回复
<tr onMouseDown="" onMouseOut="change(this);">
<script language="javascript">
function change(ele)
{
ele.style.backgroundColor="原来的颜色";
}
</script>

87,988

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧