先做兩個空格看看

結果如下

讓加法跑出來 程式碼如下

<!DOCTYPE html >
<html >
<head>
    <title>加法運算器</title>
<script>
 function add()  {
            var a = parseInt(document.getElementById('a').value);
            var b = parseInt(document.getElementById('b').value);
            document.getElementById('result').value =  a+b ;
        }
</script>
</head>
<body>
    <input id="a" type="text" />+<input id="b" type="text" />
    <button onclick="add()">=</button>
    <output id="result"></output>
</body>
</html>

執行結果

程式碼如下 可跑出你選擇的選項

<!DOCTYPE html ><html > <head> <title> Form </title> <script> function check1() { var radio1=document.getElementsByName("v1"); for(var i=0;i<radio1.length;i++){ if(radio1.item(i).checked==true) { flag1=1; alert(radio1.item(i).value); break; } } } </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="300年">300年 <input name="v1" type="radio" value="400年">400年 <input name="v1" type="radio" value="1000年">1000年 <input type="button" value="submit" onclick="check1()"/> </form> </body> </html>

 做10格題目並相加

<!DOCTYPE html ><html > <head> <title> Form </title> <script> function check() { 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; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio2.length;i++){ if(radio2.item(i).checked==true) { flag2=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio3.length;i++){ if(radio3.item(i).checked==true) { flag3=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio4.length;i++){ if(radio4.item(i).checked==true) { flag4=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio5.length;i++){ if(radio5.item(i).checked==true) { flag5=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio6.length;i++){ if(radio6.item(i).checked==true) { flag6=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio7.length;i++){ if(radio7.item(i).checked==true) { flag7=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio8.length;i++){ if(radio8.item(i).checked==true) { flag8=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio9.length;i++){ if(radio9.item(i).checked==true) { flag9=1+i; //alert(radio1.item(i).value); break; } } for(var i=0;i<radio10.length;i++){ if(radio10.item(i).checked==true) { flag10=1+i; //alert(radio1.item(i).value); break; } } document.write(flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8,flag9,flag10,"<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="1">1 <input name="v1" type="radio" value="2">2 <input name="v1" type="radio" value="3">3 <h1>2、ssss?</h1> <input name="v2" type="radio" value="1">1 <input name="v2" type="radio" value="2">2 <input name="v2" type="radio" value="3">3 <h1>3、ssss?</h1> <input name="v3" type="radio" value="1">1 <input name="v3" type="radio" value="2">2 <input name="v3" type="radio" value="3">3 <h1>4、ssss?</h1> <input name="v4" type="radio" value="1">1 <input name="v4" type="radio" value="2">2 <input name="v4" type="radio" value="3">3 <h1>5、ssss?</h1> <input name="v5" type="radio" value="1">1 <input name="v5" type="radio" value="2">2 <input name="v5" type="radio" value="3">3 <h1>6、ssss?</h1> <input name="v6" type="radio" value="1">1 <input name="v6" type="radio" value="2">2 <input name="v6" type="radio" value="3">3 <h1>7、ssss?</h1> <input name="v7" type="radio" value="1">1 <input name="v7" type="radio" value="2">2 <input name="v7" type="radio" value="3">3 <h1>8、ssss?</h1> <input name="v8" type="radio" value="1">1 <input name="v8" type="radio" value="2">2 <input name="v8" type="radio" value="3">3 <h1>9、ssss?</h1> <input name="v9" type="radio" value="1">1 <input name="v9" type="radio" value="2">2 <input name="v9" type="radio" value="3">3 <h1>10、ssss?</h1> <input name="v10" type="radio" value="1">1 <input name="v10" type="radio" value="2">2 <input name="v10" type="radio" value="3">3 <input type="button" value="submit" onclick="check()"/> </form> </body> </html>

結果如下

 

arrow
arrow
    全站熱搜

    子婷 發表在 痞客邦 留言(0) 人氣()