关于全局变量... <body>aa = ""function f1(){aa=1}function f2(){aa = 2}</body> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前面若不加var,即便在函数体里面用也被看做全局变量 <html><head><script>function foo0(strID){ var nColumn = 4; for(var i=0;i<nColumn;i++) window.document.all(strID + i).color = "yellow";}function foo1(strID,strColor){ var nColumn = 4; for(var i=0;i<nColumn;i++) window.document.all(strID + i).color = strColor;}</script></head><body><table border="1" width="100%" > <tr id="aa" onMouseOver="foo0('aa')" onMouseOut="foo1('aa','red')"> <td width="25%"><font id=aa0 color=red>aaaa</font></td> <td width="25%"><font id=aa1 color=red>bbbb</font></td> <td width="25%"><font id=aa2 color=red>cccc</font></td> <td width="25%"><font id=aa3 color=red>dddd</font></td> </tr> <tr id="aa" onMouseOver="foo0('bb')" onMouseOut="foo1('bb','blue')"> <td width="25%"><font id=bb0 color=blue>eeee</font></td> <td width="25%"><font id=bb1 color=blue>ffff</font></td> <td width="25%"><font id=bb2 color=blue>gggg</font></td> <td width="25%"><font id=bb3 color=blue>hhhh</font></td> </tr> <tr id="aa" onMouseOver="foo0('cc')" onMouseOut="foo1('cc','red')"> <td width="25%"><font id=cc0 color=red>iiii</font></td> <td width="25%"><font id=cc1 color=red>jjjj</font></td> <td width="25%"><font id=cc2 color=red>kkkk</font></td> <td width="25%"><font id=cc3 color=red>llll</font></td> </tr></table></body></html> to zhfkiller(杀手) 谢谢您的关注!能否不用给元素指定ID,而且是改变bgcolor 没有按你的颜色来调,不过你改一下就行啦。。<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script language="JavaScript"> function changecolor() { this.style.backgroundColor="#ffffff"; //var oldHandler=t.on } function restorecolor() { var a=this.rowIndex; a%2==0?document.all.tab1.rows[a].style.backgroundColor="#cccccc":document.all.tab1.rows[a].style.backgroundColor="#dddddd" }</script></head><body><table width="100%" border="1" id="tab1"> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> <tr> <td>3</td> </tr> <tr> <td>4</td> </tr> <tr> <td>5</td> </tr> <tr> <td>6</td> </tr> <tr> <td>7</td> </tr> <tr> <td>8</td> </tr> <tr> <td>9</td> </tr> <tr> <td>10</td> </tr></table><script language="JavaScript"> for (var i=0;i<document.all.tab1.rows.length;i++) { i%2==0?document.all.tab1.rows[i].style.backgroundColor="#cccccc":document.all.tab1.rows[i].style.backgroundColor="#dddddd" document.all.tab1.rows[i].onmouseover=changecolor; document.all.tab1.rows[i].onmouseout=restorecolor; }</script></body></html> //如果表格中的行(row)有HTML性质设置的oumouseover、onmouseout事件,则用下面的程序会把HTML性质设置的替代掉,下面的是加入解决该问题的代码。<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script language="JavaScript"> function addoldfunction1() { var oldhandler=this.onmouseover; this.onmouseover=function(){oldhandler();changecolor(this);} } function addoldfunction2() { var oldhandler=this.onmouseout; this.onmouseout=function(){oldhandler();restorecolor(this);} } function changecolor(t) { t.style.backgroundColor="#ffffff";//改为白色 } function restorecolor(t) { var a=t.rowIndex; a%2==0?document.all.tab1.rows[a].style.backgroundColor="#cccccc":document.all.tab1.rows[a].style.backgroundColor="#dddddd" }</script></head><body><table width="100%" border="1" id="tab1"> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> <tr> <td>3</td> </tr> <tr> <td>4</td> </tr> <tr> <td>5</td> </tr> <tr> <td>6</td> </tr> <tr onm> <td>7</td> </tr> <tr> <td>8</td> </tr> <tr> <td>9</td> </tr> <tr> <td>10</td> </tr></table><script language="JavaScript"> for (var i=0;i<document.all.tab1.rows.length;i++) { i%2==0?document.all.tab1.rows[i].style.backgroundColor="#cccccc":document.all.tab1.rows[i].style.backgroundColor="#dddddd" document.all.tab1.rows[i].onmouseover=addoldfunction1; document.all.tab1.rows[i].onmouseout=addoldfunction2; }</script></body></html> js网页打印 为什么要new一下? 动态生成div的问题 如何控制表格宽度,详细内容请进帖 ajax 实现级联菜单的形式,为什么总执行最后一行代码? 求一个正则表达式,20分给第一个正确答案 想要改变层一个图片的SRC属性要怎么设? div 内部的select 的下拉选项 失焦 obj.method()函数里的this,应该是指? JAVASCRIPT打开的窗口如何居中显示? 请问javacript在""中怎么使用变量? 如何取得一个列表的所有的可选的值?如何在JS中对它进行修改(增加、减少)?
<head>
<script>
function foo0(strID){
var nColumn = 4;
for(var i=0;i<nColumn;i++)
window.document.all(strID + i).color = "yellow";
}
function foo1(strID,strColor){
var nColumn = 4;
for(var i=0;i<nColumn;i++)
window.document.all(strID + i).color = strColor;
}
</script>
</head><body><table border="1" width="100%" >
<tr id="aa" onMouseOver="foo0('aa')" onMouseOut="foo1('aa','red')">
<td width="25%"><font id=aa0 color=red>aaaa</font></td>
<td width="25%"><font id=aa1 color=red>bbbb</font></td>
<td width="25%"><font id=aa2 color=red>cccc</font></td>
<td width="25%"><font id=aa3 color=red>dddd</font></td>
</tr>
<tr id="aa" onMouseOver="foo0('bb')" onMouseOut="foo1('bb','blue')">
<td width="25%"><font id=bb0 color=blue>eeee</font></td>
<td width="25%"><font id=bb1 color=blue>ffff</font></td>
<td width="25%"><font id=bb2 color=blue>gggg</font></td>
<td width="25%"><font id=bb3 color=blue>hhhh</font></td>
</tr>
<tr id="aa" onMouseOver="foo0('cc')" onMouseOut="foo1('cc','red')">
<td width="25%"><font id=cc0 color=red>iiii</font></td>
<td width="25%"><font id=cc1 color=red>jjjj</font></td>
<td width="25%"><font id=cc2 color=red>kkkk</font></td>
<td width="25%"><font id=cc3 color=red>llll</font></td>
</tr>
</table>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="JavaScript">
function changecolor()
{
this.style.backgroundColor="#ffffff";
//var oldHandler=t.on
}
function restorecolor()
{
var a=this.rowIndex;
a%2==0?document.all.tab1.rows[a].style.backgroundColor="#cccccc":document.all.tab1.rows[a].style.backgroundColor="#dddddd"
}
</script>
</head>
<body>
<table width="100%" border="1" id="tab1">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td>8</td>
</tr>
<tr>
<td>9</td>
</tr>
<tr>
<td>10</td>
</tr>
</table>
<script language="JavaScript">
for (var i=0;i<document.all.tab1.rows.length;i++)
{
i%2==0?document.all.tab1.rows[i].style.backgroundColor="#cccccc":document.all.tab1.rows[i].style.backgroundColor="#dddddd"
document.all.tab1.rows[i].onmouseover=changecolor;
document.all.tab1.rows[i].onmouseout=restorecolor;
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="JavaScript">
function addoldfunction1()
{
var oldhandler=this.onmouseover;
this.onmouseover=function(){oldhandler();changecolor(this);}
}
function addoldfunction2()
{
var oldhandler=this.onmouseout;
this.onmouseout=function(){oldhandler();restorecolor(this);}
}
function changecolor(t)
{
t.style.backgroundColor="#ffffff";//改为白色
}
function restorecolor(t)
{
var a=t.rowIndex;
a%2==0?document.all.tab1.rows[a].style.backgroundColor="#cccccc":document.all.tab1.rows[a].style.backgroundColor="#dddddd"
}
</script>
</head>
<body>
<table width="100%" border="1" id="tab1">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr onm>
<td>7</td>
</tr>
<tr>
<td>8</td>
</tr>
<tr>
<td>9</td>
</tr>
<tr>
<td>10</td>
</tr>
</table>
<script language="JavaScript">
for (var i=0;i<document.all.tab1.rows.length;i++)
{
i%2==0?document.all.tab1.rows[i].style.backgroundColor="#cccccc":document.all.tab1.rows[i].style.backgroundColor="#dddddd"
document.all.tab1.rows[i].onmouseover=addoldfunction1;
document.all.tab1.rows[i].onmouseout=addoldfunction2;
}
</script>
</body>
</html>