我说说做法吧,一般都是这样:用javascript的全局变量保存当前行原来的背景,一旦发生了别的事件,再把背景还原回去。
至于复选框选中,给复选框一个属性,
<input id="test" type="checkbox" name="checkall" value="checkbox" onClick="checkall(this.form)" />在选中表格某一行的事件中这样写:
document.all.test.checked = true;
不知道你问的是不是这个意思,因为有些不太清楚你说的选中是什么意思,是鼠标移上去还是点下?改变背景是只改背景色还是要改前景色?比较好的写法是给<tr>也加上id属性,操作同样。
至于复选框选中,给复选框一个属性,
<input id="test" type="checkbox" name="checkall" value="checkbox" onClick="checkall(this.form)" />在选中表格某一行的事件中这样写:
document.all.test.checked = true;
不知道你问的是不是这个意思,因为有些不太清楚你说的选中是什么意思,是鼠标移上去还是点下?改变背景是只改背景色还是要改前景色?比较好的写法是给<tr>也加上id属性,操作同样。
<tr bgcolor="#EEEEEE" onDblClick="modify(<%= rs1("id") %>)" onmouseover="this.style.background='#33ccff'" onMouseOut="this.style.background='#EEEEEE'" onMouseDown="this.style.background='#ffcc99'">
问题是,执行onMouseDown="this.style.background='#ffcc99'"后,颜色是变了,不过由于执行了onMouseOut,颜色又变成了#EEEEEE,现在如何在onmousedown按下行写个函数才行。就是不懂如何写啊。
效果在一个网站上有,你可以去看看,不过我不会实现啊。
网址是www.microsystem.cn/vmlchart,上面有很多统计图,系统入口在最下面的几行,有个demo.
<script language=javascript>
var orObj;
var orBg;function changeBg(obj){
//以前选中的一行复元
if(orObj){
orObj.style.backgroundColor=orBg;
}//保存当前对象和背景色
orObj = obj;
orBg = obj.style.backgroundColor;//当前行变色
obj.style.backgroundColor='#33ccff';}
</script><table>
<tr bgcolor="#EEEEEE" onclick="changeBg(this)">
<td>test</td>
<tr>
<tr bgcolor="#EEEEEE" onclick="changeBg(this)">
<td>test1</td>
<tr>
</table>
后,背景又变回原来的了。鼠标移到当前行是一个颜色,单击当前行后又是一个颜色,同时鼠标能移动
<table>
<tr bgcolor="#EEEEEE" onclick="changeBg(this)">
<td>test</td>
<tr>
<tr bgcolor="#EEEEEE" onclick="changeBg(this)">
<td>test1</td>
<tr>
</table>
这一句加上onmouseover="this.style.background='#33ccff'" onMouseOut="this.style.background='#EEEEEE'" 后就不行了
var orBg;
var orBg1;
var orBg2;function changeBg2(obj1){ orBg1=obj1.style.backgroundColor;
if(orBg1!='#33ccff')
orBg2=orBg1;
if((orBg1!='#ffcc99')&&(orBg1!='#33ccff'))
{
obj1.style.backgroundColor='#33ccff';
}
else if(orBg1=='#33ccff')
{
obj1.style.backgroundColor=orBg2;
}
}
function changeBg1(obj){if(orObj){
orObj.style.backgroundColor=orBg1;
}
//orBg = obj.style.backgroundColor;
orObj = obj;obj.style.backgroundColor='#ffcc99';
}
body下用:
<tr bgcolor="#EEEEEE" onDblClick="modify(<%= rs1("id") %>)" onclick="changeBg1(this)" onMouseOver="changeBg2(this)" onmouseout="changeBg2(this)">