2016年6月3日 星期五

6/3亂數不重複

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>隨機產生亂數</title>
<Script type ="text/javascript">
  var a=0,b=0,c=0;
  var minNum = 0;
  var maxNum = 7;
function add(){

        a = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
        b = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
        c = Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
        if(b==a)
        {b=b+1;}
        if(c==a)
        {c=c+2;}
        if(c==b)
        {c=c+1;}
     

  document.write("亂數",+a,+b,+c);
}
 </Script>

</head>
<input type="button" value="submit" onclick="add()"/>
<body>

<h2>亂數不重複</h2>
</body>
</html>

2016年5月19日 星期四

5/20圓餅圖統計

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

    <script type="text/javascript">


      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      var a,b,c;
      a=0;
      b=0;
      c=0;
      function add() {
   
 var radio1 = document.getElementsByName("v1");
 var radio2 = document.getElementsByName("v2");
 var radio3 = document.getElementsByName("v3");


   for(var i=0;i<radio1.length;i++)
   {
     if(radio1.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;

break;
     }
   }
   for(var i=0;i<radio2.length;i++)
   {
     if(radio2.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
         document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;

break;
     }
   }
   for(var i=0;i<radio3.length;i++)
   {
     if(radio3.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;
break;
     }
   }







      drawChart();
      }

      function drawChart() {
     
       var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     a],
          ['Eat',      b],
          ['Commute',  c],
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>

<h1>你選了什麼?</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年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年">300年        
<input name="v2" type="radio" value="400年">400年          
<input name="v2" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年">300年        
<input name="v3" type="radio" value="400年">400年          
<input name="v3" type="radio" value="1000年">1000年
<br>


c1:
 <input type="text" name="FirstName" id="c1" <br><br/>

 c2:
 <input type="text" name="address" id="c2" <br></br>

 c3:
 <input type="text" name="address" id="c3" <br></br>


 <input type="button" value="submit" onclick="add()"/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>

  </body>
</html>


<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

    <script type="text/javascript">


      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      var a,b,c;
      a=0;
      b=0;
      c=0;
var n1=n2=n3=n4=0;

function Random() {

var maxNum = 4;
var minNum = 0;
    n1 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n2 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n3 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n4= Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
      drawChart();

}
      function add() {
   
 var radio1 = document.getElementsByName("v1");
 var radio2 = document.getElementsByName("v2");
 var radio3 = document.getElementsByName("v3");


   for(var i=0;i<radio1.length;i++)
   {
     if(radio1.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;

break;
     }
   }
   for(var i=0;i<radio2.length;i++)
   {
     if(radio2.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
         document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;

break;
     }
   }
   for(var i=0;i<radio3.length;i++)
   {
     if(radio3.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


   
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;
break;
     }
   }







      drawChart();
      }

      function drawChart() {
     
       var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     n1],
          ['Eat',      n2],
          ['Commute',  n3],
         ['an',  n4],

        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>

<h1>你選了什麼?</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年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年">300年        
<input name="v2" type="radio" value="400年">400年          
<input name="v2" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年">300年        
<input name="v3" type="radio" value="400年">400年          
<input name="v3" type="radio" value="1000年">1000年
<br>


c1:
 <input type="text" name="FirstName" id="c1" <br><br/>

 c2:
 <input type="text" name="address" id="c2" <br></br>

 c3:
 <input type="text" name="address" id="c3" <br></br>


 <input type="button" value="submit" onclick="add()"/>
 <input type="button" value="random" onclick="Random()"/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>

  </body>
</html>


2016年5月12日 星期四

5/13圓餅圖

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

 function add() {
            var a ;
            var b ;
            alert('result value');
}

                 function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     2],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    2]
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
    <input type="button" value="submit" onclick="add()"/>
  </body>
</html>


2016年5月5日 星期四

5/6答案總合

<!DOCTYPE html >
<html >
<head>
    <title>加法運算器</title>
<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>


<!DOCTYPE html >
<html >
<head>
    <title>
Form
</title>
    <script>
        function check() {
            var radio1=document.getElementsByName("v1");
            var radio2=document.getElementsByName("v2");
   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(radio2.item(i).value);
                  break;
       }
   }
  document.write(flag1,flag2);
}
    </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

<input type="button" value="submit" onclick="check()"/>

</form>
</body>
</html>

<!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(radio2.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio3.length;i++)
   {
         if(radio3.item(i).checked==true)
             {
     flag3=1+i;
     //alert(radio3.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio4.length;i++)
   {
         if(radio4.item(i).checked==true)
             {
     flag4=1+i;
     //alert(radio4.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio5.length;i++)
   {
         if(radio5.item(i).checked==true)
             {
     flag5=1+i;
     //alert(radio5.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio6.length;i++)
   {
         if(radio6.item(i).checked==true)
             {
     flag6=1+i;
     //alert(radio6.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio7.length;i++)
   {
         if(radio7.item(i).checked==true)
             {
     flag7=1+i;
     //alert(radio7.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio8.length;i++)
   {
         if(radio8.item(i).checked==true)
             {
     flag8=1+i;
     //alert(radio8.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio9.length;i++)
   {
         if(radio9.item(i).checked==true)
             {
     flag9=1+i;
     //alert(radio9.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio10.length;i++)
   {
         if(radio10.item(i).checked==true)
             {
     flag10=1+i;
     //alert(radio10.item(i).value);
                  break;
       }
   }
  document.write(flag1,flag2,flag3,flag4,flag5,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="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>

2016年4月28日 星期四

4/29問卷單選題

http://pclevin.blogspot.tw/2011/12/javascriptjavascript.html
貼在wordpad上 另存新檔 test.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">
  document.write("Hello world!!");
 </Script>
</body>
</html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<input type="checkbox" name="interest" value="單 打 獨 鬥" id="1"><label for="1">單 打 獨 鬥---------------</label><label for="demoradio_1">

<div class="qheader">
1) What is the difference between a jungle and a rain forest?</div>
<div class="qselections">
<input type="radio" value="a" name="question1">a) No difference. Simply two different ways in referring to the same thing.<br>
<input type="radio" value="b" name="question1">b) A jungle in general receives less rain than a rain forest.<br>
<input type="radio" value="c" name="question1">c) A jungle refers to the thickest area of a rain forest<br>
<input type="radio" value="d" name="question1">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
</div>

<br>

<h2>document.write用法</h2>
 <Script type ="text/javascript">
  document.write("Hello world!!");
 </Script>
</body>
</html>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">
  document.write("Hello world!!");
 function myFunInput(obj){
   obj
   alert("你的id編號為:"+obj.id);
  }
 </Script>
<input type="button" value="請點擊" id="myId" onClick="myFunInput(this)">
</body>
</html>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">

 </Script>
<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 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>