practice14(구구단 업글).html 1.1 KB
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>구구단</title>
</head>

<body>
    <div id="div1">
        <h1>** 구구단 출력 **</h1>
    </div>
    <div id="div2">
        단:<select class="" name="dan" onchange="selectEvent(this)">
        <option value="2">2단</option>
        <option value="3">3단</option>
        <option value="4" selected>4단</option>
        <option value="5">5단</option>
        <option value="6">6단</option>
        <option value="7">7단</option>
        <option value="8">8단</option>
        <option value="9">9단</option>

      </select>
    </div>
    <div id="div3">

    </div>
    <script type="text/javascript">
    function selectEvent(selectObj) {
      var value = selectObj.value;
      func(value);
			}
        function func(number) {
            var total = "";
            var temp= "";
            for(var i = 1; i <= 9; i++){
              temp+=( number + " * " + i + " = " + number*i + "<br>")
            }

            total +=temp;
            document.getElementById("div3").innerHTML = total;
        }
    </script>
</body>

</html>