这个还没有写完善,你可以加工一下。
对于第三点,你可以设置一个全局变量做为标志。
以下可以做为参考
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!--
function test1(obj)
{
obj.bgColor="#000000";
}
function test2(obj)
{
obj.bgColor="#ffffff";
}
function test3(obj)
{
alert("aa");
obj.bgColor="#ff0000";
document.all.tr_b.bgColor="#ffffff"
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<table>
<tr id="tr_a" bgColor="blue" onmouseover="test1(this)" onmouseout="test2(this)" onclick="test3(this)" style="cursor:hand">
<td>aaaaaaaaaaaaaaa</td></tr>
<tr id="tr_b" style="cursor:hand"><td>bbbbbbbbbbbbbbbbbb</td></tr>
</table>
</BODY>
</HTML>
对于第三点,你可以设置一个全局变量做为标志。
以下可以做为参考
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!--
function test1(obj)
{
obj.bgColor="#000000";
}
function test2(obj)
{
obj.bgColor="#ffffff";
}
function test3(obj)
{
alert("aa");
obj.bgColor="#ff0000";
document.all.tr_b.bgColor="#ffffff"
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<table>
<tr id="tr_a" bgColor="blue" onmouseover="test1(this)" onmouseout="test2(this)" onclick="test3(this)" style="cursor:hand">
<td>aaaaaaaaaaaaaaa</td></tr>
<tr id="tr_b" style="cursor:hand"><td>bbbbbbbbbbbbbbbbbb</td></tr>
</table>
</BODY>
</HTML>
function Mover(go){go.bgColor="#ebe9e0";}
function Mout1(come){come.bgColor="#ffffff";}
function Mout2(come){come.bgColor="#e9f4ff";}
</script>< td bgColor="#e9f4ff" onmouseover="javascript:Mover(this)" onmouseout="Mout2(this)">baisun</td>
onclick和onmouseout有点冲突,必须设置标志或参数来解决。
因为click完,鼠标移出tr又触发了onmouseout事件。
onmouseover的时候也有类似问题
有什么好办法我还没有想到。应该可以加全局变量实现。
var flag=1
function Mover(go){if(flag==1) go.bgColor="#ebe9e0";}
function Mout2(come){if(flag==1) come.bgColor="#e9f4ff";}
</script>
< td id=tr_A bgColor="#e9f4ff" onmouseover="javascript:Mover(this)" onmouseout="Mout2(this)" onclick="this.bgColor='#FF0000';document.all.tr_B.bgColor='#ffffff';flag=0;">baisun</td>
< td id=tr_B bgColor="#e9f4ff" onmouseover="javascript:Mover(this)" onmouseout="Mout2(this)" onclick="javascript:flag=(flag==0)?1:0;">baisun</td>
2楼的,你说定义全局变量来做,我似乎有点眉目,可否再继续说明白点?
还有,用你写的代码无法实现啊……
我说了那只能作为参考的阿。
不能光在click里调用mouseout就行了,那样,鼠标out的时候还是会有
mouseout事件。设置颜色为全局变量,做为参数,改变参数值能解决这个问题。 我只是提出我个人的解决的思路,没有完全写出代码。见谅!
<script>
var lock=false;
function hi(obj){lock=false;obj.bgColor='red'}
function ove(obj){if(!lock)obj.bgColor='black';}
function ou(obj){if(!lock)obj.bgColor='white';}
function hit(obj){document.all['trb'].bgColor='white';obj.bgColor='white';lock=true}
</script><table border="1" width="100">
<tr>
<td width="100%" id="trb" bgcolor="red" onclick="hi(this)">b </td>
</tr>
<tr>
<td width="100%" bgcolor="white" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
</table>
</body>
我要求这个过程是循环的。麻烦大家再继续帮帮忙,搞定后所有人都有最少10分,不够我再加!
试试
<script>
var lock=false
var h="trb"
function ove(obj){if(obj.id==h)return;else lock=false;if(!lock)obj.bgColor='black'}
function ou(obj){if(obj.id==h)return;else lock=false;if(!lock)obj.bgColor='white';}
function hit(obj){lock=false;document.all(h).bgColor='white';h=obj.id;obj.bgColor='red';lock=true}
</script><table border="1" width="100">
<tr>
<td width="100%" id="trb" bgcolor="red" onclick="hit(this)" onmouseover="ove(this)" onmouseout="ou(this)">b </td>
</tr>
<tr>
<td width="100%" id="tra" bgcolor="white" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
</table>
</body>
<body>
试试
<script>
var lock=false
var h="trb"
function ove(obj){if(obj.id==h)return;else lock=false;if(!lock)obj.bgColor='black'}
function ou(obj){if(obj.id==h)return;else lock=false;if(!lock)obj.bgColor='white';}
function hit(obj){lock=false;document.all(h).bgColor='white';h=obj.id;obj.bgColor='red';lock=true}
</script><table border="1" width="100">
<tr>
<td width="100%" id="trb" bgcolor="red" onclick="hit(this)" onmouseover="ove(this)" onmouseout="ou(this)">b </td>
</tr>
<tr>
<td width="100%" id="tra" bgcolor="white" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
<tr>
<td width="100%" id="trc" bgcolor="white" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
<tr>
<td width="100%" id="trd" bgcolor="white" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
</table>
</body>
<body onload="init()">
<script>
var h="tra"
function init(){if(h)document.all(h).bgColor="red"}
function ove(obj){if(!h){obj.bgColor='black';return;}if(obj.id==h)return;else obj.bgColor='black'}
function ou(obj){if(obj.id==h)return;else obj.bgColor='white'}
function hit(obj){if(!h)h=obj.id;lock=false;document.all(h).bgColor='white';h=obj.id;obj.bgColor='red'}
</script>
<table border="1" width="100">
<tr>
<td width="100%" id="trb" onclick="hit(this)" onmouseover="ove(this)" onmouseout="ou(this)">b </td>
</tr>
<tr>
<td width="100%" id="tra" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">a </td>
</tr>
<tr>
<td width="100%" id="trc" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">c </td>
</tr>
<tr>
<td width="100%" id="trd" onmouseover="ove(this)" onmouseout="ou(this)" onclick="hit(this)">d </td>
</tr>
</table>
</body>
结贴!我单独开一贴,请fason(阿信)一个人来拿分!
其余人就在这张帖子结了。