1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>获取选择框信息</title> 6 <script language="javascript"> 7 function show(){ 8 var name=document.myform.name.value; 9 alert(name); 10 11 var sex 12 if(document.myform.sex[0].checked){ 13 sex=document.myform.sex[0].value; 14 }else{ 15 sex=document.myform.sex[1].value; 16 } 17 alert(sex); 18 19 var hobby=""; 20 for(i=0;i<document.myform.interesting.length;i++){ //循环遍历 21 if(document.myform.interesting[i].checked){ //判断是否被选中 22 hobby+=document.myform.interesting[i].value+"、" //选中加入hobby中 23 } 24 } 25 alert(hobby); 26 27 var area=document.myform.result.value; 28 alert(area); 29 } 30 31 function local(val){ 32 document.myform.result.value=val; 33 } 34 35 </script> 36 37 </head> 38 <body> 39 <form action="#" method="post" name="myform"> 40 姓名: 41 <input type="text" name="name"> <br/> 42 性别: 43 <input type="radio" name="sex" value="男" checked>男 44 <input type="radio" name="sex" value="女">女 <br/> 45 爱好: 46 <input type="checkbox" name="interesting" value="听音乐">听音乐 47 <input type="checkbox" name="interesting" value="看电影">看电影 48 <input type="checkbox" name="interesting" value="玩游戏">玩游戏 49 <input type="checkbox" name="interesting" value="看书">看书<br/> 50 地区: 51 <select name="area" onchange="local(this.value)"> <br/> 52 <option>=请选择=</option> 53 <option value="济南">济南</option> 54 <option value="青岛">青岛</option> 55 <option value="威海">威海</option> 56 </select> 57 <input type="text" name="result" readonly><br/> 58 59 <input type="button" value="显示内容" onclick="show()"> 60 61 </form> 62 </body> 63 </html>
1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>获取选择框信息</title> 6 <script language="javascript"> 7 function show(){ 8 var name=document.myform.name.value; 9 alert(name); 10 11 var sex 12 if(document.myform.sex[0].checked){ 13 sex=document.myform.sex[0].value; 14 }else{ 15 sex=document.myform.sex[1].value; 16 } 17 alert(sex); 18 19 var hobby=""; 20 for(i=0;i<document.myform.interesting.length;i++){ 21 if(document.myform.interesting[i].checked){ 22 hobby+=document.myform.interesting[i].value+"、" 23 } 24 } 25 alert(hobby); 26 27 var area=document.myform.result.value; 28 alert(area); 29 } 30 31 function local(val){ 32 document.myform.result.value=val; 33 } 34 35 </script> 36 37 </head> 38 <body> 39 <form action="#" method="post" name="myform"> 40 姓名: 41 <input type="text" name="name"> <br/> 42 性别: 43 <input type="radio" name="sex" value="男" checked>男 44 <input type="radio" name="sex" value="女">女 <br/> 45 爱好: 46 <input type="checkbox" name="interesting" value="听音乐">听音乐 47 <input type="checkbox" name="interesting" value="看电影">看电影 48 <input type="checkbox" name="interesting" value="玩游戏">玩游戏 49 <input type="checkbox" name="interesting" value="看书">看书<br/> 50 地区: 51 <select name="area" onchange="local(this.value)"> <br/> 52 <option>=请选择=</option> 53 <option value="济南">济南</option> 54 <option value="青岛">青岛</option> 55 <option value="威海">威海</option> 56 </select> 57 <input type="text" name="result" readonly><br/> 58 59 <input type="button" value="显示内容" onclick="show()"> 60 61 </form> 62 </body> 63 </html>
时间: 2024-10-16 00:18:19