日期:2014-05-16  浏览次数:20367 次

我的笔记一 -------用javascript实现全选框和按钮在没有选项时变灰
<script>
//按钮在没有选项时变灰
function isCheck()

{
var checks = document.getElementsByName("allcheckbox");
for(var i=0; i<checks.length ; i++)
{
    if(checks[i].checked == false)
{  
var mod=document.getElementById("modify");
    var del=document.getElementById("del");
mod.disabled = true;
del.disabled = true;
mod.style.color = "#dad8c9";
del.style.color = "#dad8c9";
}else
{  
    var mod=document.getElementById("modify");
    var del=document.getElementById("del");    
    mod.disabled = false;
del.disabled = false;
mod.style.color = "#000000";
del.style.color = "#000000";
break;
}

}
}
//全选框
function isAllCheck()
{
  
var checks1 = document.getElementById("allcheckbox00");
var checks2 = document.getElementsByName("allcheckbox");
if (checks1.checked)
{

for(var i=0; i<checks2.length ; i++)
{
checks2[i].checked = true;
}
}else{
for(var i=0; i<checks2.length ; i++)
{
checks2[i].checked = false;
}
}
isCheck();
}
</script>
<input type="button" id="modify" style="color:#dad8c9" disabled="true" name="modify" value="修改" >
<input type="button" id="del" style="color:#dad8c9" disabled="true" name="modify" value="删除" >
<input type="checkbox" id="allcheckbox00" name="allcheckbox00"
onclick="isAllCheck();" >

<input type="checkbox"  id="allcheckbox01" name="allcheckbox" onclick="isCheck();">