在HTML里怎样让鼠标移上去变颜色
1个回答
2013-04-01
展开全部
表格行指向变色,请运行偶写的代码: <script type="text/javascript">
function table_tr_changec(){
var tableObj=document.getElementById('de_table') ;
var tableobj_tr=tableObj.getElementsByTagName('tr');
var tableobj_tr_len=tableobj_tr.length;
var hover_color='#FF0000';
var normal_color='#FFFFFF';
for(var i=0;i<tableobj_tr_len;i++){
this.flog=0;
tableobj_tr[i].onmouseover=function (){
this.style.cursor='pointer';
this.flog=1;
if(this.flog==1){
this.style.backgroundColor=hover_color;
}
}
tableobj_tr[i].onmouseout=function (){
this.flog=0;
this.style.backgroundColor=normal_color;
}
}
} var ta_lock;
function table_hover(){
ta_lock=setInterval("table_tr_changec()");
}
function table_out(){
clearInterval(ta_lock);
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="de_table" onmouseover="table_hover()" onmouseout="table_out()">
<tr>
<td>dfdf</td>
<td>dsf</td>
</tr>
<tr>
<td>fdsf</td>
<td>sdf</td>
</tr>
<tr>
<td>sdfs</td>
<td>sdfsd</td>
</tr>
</table>
function table_tr_changec(){
var tableObj=document.getElementById('de_table') ;
var tableobj_tr=tableObj.getElementsByTagName('tr');
var tableobj_tr_len=tableobj_tr.length;
var hover_color='#FF0000';
var normal_color='#FFFFFF';
for(var i=0;i<tableobj_tr_len;i++){
this.flog=0;
tableobj_tr[i].onmouseover=function (){
this.style.cursor='pointer';
this.flog=1;
if(this.flog==1){
this.style.backgroundColor=hover_color;
}
}
tableobj_tr[i].onmouseout=function (){
this.flog=0;
this.style.backgroundColor=normal_color;
}
}
} var ta_lock;
function table_hover(){
ta_lock=setInterval("table_tr_changec()");
}
function table_out(){
clearInterval(ta_lock);
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="de_table" onmouseover="table_hover()" onmouseout="table_out()">
<tr>
<td>dfdf</td>
<td>dsf</td>
</tr>
<tr>
<td>fdsf</td>
<td>sdf</td>
</tr>
<tr>
<td>sdfs</td>
<td>sdfsd</td>
</tr>
</table>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询