dddd

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<styletype="text/css"media="all">

label{

cursor:pointer;

font-size:12px;

margin:0px2px0px0px;

color:#2B86BD;

}

.d0{

margin-bottom:30px;

}

.d0input{

cursor:pointer;

margin:0px;

padding:0px2px;

}

</style>

<scriptlanguage="javascript"type="text/javascript">

vardr=document.getElementsByTagName("div"),i,t="";

functionsubmit1(num,type){

t="";

vardri=dr[num].getElementsByTagName("input");

for(i=0;i<dri.length;i++){

if(dri[i].checked){

if(type==0){

alert(dri[i].value);

break;

}else{

t=t+dri[i].value+";";

}

}

}

if(type==1)alert(t);

}

//ChangeSelect

submit1.allselect=function(){

vardrc=dr[1].getElementsByTagName("input");

for(i=0;i<drc.length;i++){

drc[i].checked=true;

}

}

//allNot

submit1.allNot=function(){

vardrc=dr[1].getElementsByTagName("input");

for(i=0;i<drc.length;i++){

drc[i].checked=false;

}

}

//reverse

submit1.reverseSelect=function(){

vardrc=dr[1].getElementsByTagName("input");

for(i=0;i<drc.length;i++){

if(drc[i].checked){

drc[i].checked=false;

}else{

drc[i].checked=true;

}

}

}

</script>

<title>js获取单选框、复选框的值及操作</title>

</head>

<body>

<divclass="d0">

<inputtype="radio"name="day"id="r0"value="前天"/><labelfor="r0">前天</label>

<inputtype="radio"name="day"id="r1"value="昨天"/><labelfor="r1">昨天</label>

<inputtype="radio"name="day"id="r2"checked="checked"value="今天"/><labelfor="r2">今天</label>

<inputtype="radio"name="day"id="r3"value="明天"/><labelfor="r3">明天</label>

<inputtype="radio"name="day"id="r4"value="后天"/><labelfor="r4">后天</label>

<buttontype="button"onclick="submit1(0,0)">提交</button>

</div>

<div>

<inputtype="checkbox"value="前年"/><label>前年</label>

<inputtype="checkbox"value="去年"/><label>去年</label>

<inputtype="checkbox"value="今年"/><label>今年</label>

<inputtype="checkbox"value="明年"/><label>明年</label>

<inputtype="checkbox"value="后年"/><label>后年</label>

<buttontype="button"onclick="submit1(1,1)">提交</button>

<buttontype="button"onclick="submit1.allselect()">全选</button>

<buttontype="button"onclick="submit1.reverseSelect()">反选</button>

<buttontype="button"onclick="submit1.allNot()">全不选</button>

</div>

</body>

</html>

相关推荐