2016年5月13日 星期五

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>

<form action="#" method="post" class="demoForm" id="demoForm">
    <fieldset>
        <legend>Demo: Get Value of Selected</legend>
   
    <p>Select a shipping method:</p>
    <p>
        <label><input type="radio" name="ship" value="a" checked /> a)Standard Ground</label>
        <label><input type="radio" name="ship" value="b" />b) Second Day</label>
        <label><input type="radio" name="ship" value="c" /> c)Overnight</label>
        <label><input type="radio" name="ship" value="d" /> d)Pick up</label>
    </p>
   
    <p><button type="button" name="getVal">Get Value of Selected</button></p>
   
    </fieldset>
</form>
 </Script>
<script type="text/javascript">
// to remove from global namespace
(function() {
   
    function getRadioVal(form, name) {
        var val;
        var radios = form.elements[name];
       
        for (var i=0, len=radios.length; i<len; i++) {
            if ( radios[i].checked ) {
                val = radios[i].value;
                break;
            }
        }
        return val;
    }


    document.forms['demoForm'].elements['getVal'].onclick = function() {
        alert( 'The selected radio button\'s value is: ' + getRadioVal(this.form, 'ship') );
    };
   
   
    // disable submission of all forms on this page
    for (var i=0, len=document.forms.length; i<len; i++) {
        document.forms[i].onsubmit = function() { return false; };
    }
   
}());
</script>
</body>
</html>

506

<html>
<head>
<title>
  Porm
</title>
<script>
function check1(){
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
var radio4=document.getElementsByName("v4");
var radio5=document.getElementsByName("v5");
var radio6=document.getElementsByName("v6");
var radio7=document.getElementsByName("v7");
var radio8=document.getElementsByName("v8");
var radio9=document.getElementsByName("v9");
var radio10=document.getElementsByName("v10");
   for(var i=0;i<radio1.length;i++){
         if(radio1.item(i).checked==true){
        flag1=1+i;
        break;
       }
   }
   for(var i=0;i<radio2.length;i++){
         if(radio2.item(i).checked==true){
        flag2=1+i;
                break;
       }
   }
for(var i=0;i<radio3.length;i++){
         if(radio3.item(i).checked==true){
        flag3=1+i;
                break;
       }
   }
for(var i=0;i<radio4.length;i++){
         if(radio4.item(i).checked==true){
        flag4=1+i;
                break;
       }
   }
for(var i=0;i<radio5.length;i++){
         if(radio5.item(i).checked==true){
        flag5=1+i;
                break;
       }
   }
for(var i=0;i<radio6.length;i++){
         if(radio6.item(i).checked==true){
        flag6=1+i;
                break;
       }
   }
for(var i=0;i<radio7.length;i++){
         if(radio7.item(i).checked==true){
        flag7=1+i;
                break;
       }
   }
for(var i=0;i<radio8.length;i++){
         if(radio8.item(i).checked==true){
        flag8=1+i;
                break;
       }
   }
for(var i=0;i<radio9.length;i++){
         if(radio9.item(i).checked==true){
        flag9=1+i;
                break;
       }
   }
for(var i=0;i<radio10.length;i++){
         if(radio10.item(i).checked==true){
        flag10=1+i;
                break;
       }
   }

document.write(flag1,flag2,flag3,flag4,flag5)
document.write('<br>');
document.write(flag6,flag7,flag8,flag9,flag10)
document.write('<br>');
document.write(flag1+flag2+flag3+flag4+flag5+flag6+flag7+flag8+flag9+flag10)
}
</script>
</head>
<body>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="a">a.300年          
<input name="v1" type="radio" value="b">b.400年            
<input name="v1" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>2、ssss?</h1>
<input name="v2" type="radio" value="a">a.300年          
<input name="v2" type="radio" value="b">b.400年            
<input name="v2" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>3、ssss?</h1>
<input name="v3" type="radio" value="a">a.300年          
<input name="v3" type="radio" value="b">b.400年            
<input name="v3" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>4、ssss?</h1>
<input name="v4" type="radio" value="a">a.300年          
<input name="v4" type="radio" value="b">b.400年            
<input name="v4" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>5、ssss?</h1>
<input name="v5" type="radio" value="a">a.300年          
<input name="v5" type="radio" value="b">b.400年            
<input name="v5" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>6、ssss?</h1>
<input name="v6" type="radio" value="a">a.300年          
<input name="v6" type="radio" value="b">b.400年            
<input name="v6" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>7、ssss?</h1>
<input name="v7" type="radio" value="a">a.300年          
<input name="v7" type="radio" value="b">b.400年            
<input name="v7" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>8、ssss?</h1>
<input name="v8" type="radio" value="a">a.300年          
<input name="v8" type="radio" value="b">b.400年            
<input name="v8" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>9、ssss?</h1>
<input name="v9" type="radio" value="a">a.300年          
<input name="v9" type="radio" value="b">b.400年            
<input name="v9" type="radio" value="c">c.1000年
</form>
<form action="post.php" method="post"  name="add" enctype="multipart/form-data"onSubmit="return check();" >
<h1>10、ssss?</h1>
<input name="v10" type="radio" value="a">a.300年          
<input name="v10" type="radio" value="b">b.400年            
<input name="v10" type="radio" value="c">c.1000年
<input type="button" value="submit" onclick="check1()" />
</form>
</body>
</html>