JS厉害的兄弟进来看看!

cokeyang 2003-09-20 08:00:36
<script language="javascript">
function chgColor(id)
{
var o=document.getElementById(id);
if(o.style.backgroundColor=="#ffcc99")
o.style.backgroundColor="#eeeeee";
else
o.style.backgroundColor="#ffcc99";
}

function checkall(o,checkname)
{
var a = document.getElementsByName(checkname);
for (var i=0; i<a.length; i++){
a[i].checked = o.checked;
}

}
</script>
<table width="200">
<tr style="background-color:#ffcc99" id="1">
<td><input type="checkbox" name="delid" value="ON" onclick="chgColor(1)"></td>
<td>This is a Table </td>
</tr>
<tr style="background-color:#ffcc99" id="2">
<td><input type="checkbox" name="delid" value="ON" onclick="chgColor(2)"></td>
<td>This is a Table </td>
</tr>
<tr style="background-color:#ffcc99" id="3">
<td><input type="checkbox" name="delid" value="ON" onclick="chgColor(3)"></td>
<td>This is a Table </td>
</tr>
<tr style="background-color:#ffcc99" id="4">
<td><input type="checkbox" name="delid" value="ON" onclick="chgColor(4)"></td>
<td>This is a Table </td>
</tr>
<tr style="background-color:#ffcc99" id="5">
<td><input type="checkbox" name="delid" value="ON" onclick="chgColor(5)"></td>
<td>This is a Table </td>
</tr>
</table>
全选<input type="checkbox" value="Check All" onclick="checkall(this,'delid')">
...全文
21 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SadEmprie 2003-09-20
  • 打赏
  • 举报
回复
把函数checkall改成:
function checkall(o,checkname)
{
var a = document.getElementsByName(checkname);
var tr=document.all.tags("tr");
var i=0;
for (var i=0; i<a.length; i++){
a[i].checked = o.checked;
}
for(i=0;i<tr.length;i++){
if(tr[i].style.backgroundColor=="#ffcc99")
tr[i].style.backgroundColor="#eeeeee";
else
tr[i].style.backgroundColor="#ffcc99";
}

}
cokeyang 2003-09-20
  • 打赏
  • 举报
回复
大家帮我看看呀!顶一下也非常感谢!
cokeyang 2003-09-20
  • 打赏
  • 举报
回复
楼上的兄弟谢谢你!
不过你说的不是我要的那种效果!
我想要的是hotmail.com邮箱的那种效果!

你看看我的代码就明白的!
1fairy1 2003-09-20
  • 打赏
  • 举报
回复
测试能过。
————————————————————————————
<script language=javascript>
function selectbox(){
var i=document.form.elements.length-1;
alert(i);
for(var j=0;j<=i;j++){
document.form.elements[j].checked;
}
aa.bgColor='red';
return false;
}
</script>
<form name=form onsubmit="return selectbox()">
<table id=aa><tr><td><input type=checkbox><input type=checkbox><input type=checkbox></td></tr></table>
<input type=submit value="select all">
</form>
_____________________________________________________________
结合一下这个吧。
PS:
代码太长,
没有时间看。
cokeyang 2003-09-20
  • 打赏
  • 举报
回复
我要实现的是点击全选的时候全部选这!然后表格还要变色!
现在是单个选定的时候,表格变色,全选的时候表格不变!

请高手赐教!

87,902

社区成员

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

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