实现全选,多选,反选的另一做法

有三个radio和8个文本框
点击的第一个radio的时候,8个文本框可以被编辑
点击的第二个radio的时候,其中四个文本框随机被disabled,
点击的第三个radio的时候,剩下四个文本框被disabled,原来被disabled的恢复可以编辑 

代码实现,但有缺陷,等待改建

 

< script language = " javascript " >  
function  selectIt1(action){ 
    
if (action == " selectAll " ){
    
for ( var  i = 1 ;i < 9 ;i ++ ){
    document.getElementById(
" text " + i).disabled = ""
    }
    } 
    
else   if (action == 4 ){
    
var  arr_1  =   new  Array();
var  rstArr  =   new  Array();
for ( var  i  =   1 ; i < 9 ; i ++ )
{
    arr_1[i] 
=  i;
}
for ( var  i  =   1 ; i < 5 ; i ++ )
{
    
var  z  =  Math.floor(( 9 - i) * Math.random());

    rstArr.push(arr_1[z]);
    arr_1.splice(z,
1 );
}
var  c = rstArr.join( " , " );    
a
= c.split( " , " );
var  k = 0 ;

while (k ++< 9 ){
document.getElementById(
" text " + k).disabled = ""
    
for ( var  i  in  a){
    i
= a[i];
    document.getElementById(
" text " + i).disabled = " disabled "
    alert(a)
    }
    }
    }
    
else {
    
for ( var  i = 1 ;i < 9 ;i ++ ){
    
var  dis = document.getElementById( " text " + i);
    
if (dis.disabled == true ){
    dis.disabled
= ""
    }
    
else {
    dis.disabled
= " disabled "
    }
    }
    }
    






</ script >  
< form name = " bdkey "  id = " bdkey " >  
< input name = " an1 "  type = " radio "  id = " an1 "  value = " 1 "  onClick = " selectIt1('selectAll') " >
< input name = " an1 "  type = " radio "  id = " an1 "  value = " 2 "  onClick = " selectIt1(4) " >
< input name = " an1 "  type = " radio "  id = " an1 "  value = " 3 "  onClick = " selectIt1() " >
< input name = " text1 "  type = " text "  id = " text1 "  disabled = " disabled " >
< input name = " text2 "  type = " text "  id = " text2 "  disabled = " disabled " >
< input name = " text3 "  type = " text "  id = " text3 "  disabled = " disabled " >
< input name = " text4 "  type = " text "  id = " text4 "  disabled = " disabled " >
< input name = " text5 "  type = " text "  id = " text5 "  disabled = " disabled " >
< input name = " text6 "  type = " text "  id = " text6 "  disabled = " disabled " >
< input name = " text7 "  type = " text "  id = " text7 "  disabled = " disabled " >
< input name = " text8 "  type = " text "  id = " text8 "  disabled = " disabled " >
</ form >  

你可能感兴趣的:(JavaScript,c,function,action)