본문 바로가기

JavaScript

[Javascript]기초문법 html/css/jsp 자바스크립트로 구구단 테이블 만들기

반응형

기록용

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>javascript</title>
        <script type="text/javascript">

        </script>
    </head>
    <body>
      <table align=center>
         <script>
                for (i = 1; i <= 9; i++) {

                    document.write('<tr>');
                    for (j = 2; j <= 9; j++) {
                        var k = i * j;

                        document.write('<td>' + j + 'x' + i + '=' + k + '<td>')
                    }
                }
          </script>

      </table>
    </body>
 </html>

 

 

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>javascript</title>
        <script type="text/javascript">

        </script>
        <style>
            .df{ border-collapse: collapse;}
            .line{border: 1px solid black; border-collapse: collapse;}
            .red_point{color:red;}
            .blue_point{color:blue;}
        </style>
    </head>
    <body>
        <table class="df">
            <script>
                for(j= 1; j<10; j++){
                    document.write('<tr class="add">');
                    for(i=2; i<=9; i++){
                        var n = i*j
                
                        if(n%2==0){
                           document.write('<td class="line">' + '<p style="color:red;">' + i + "*" + '&nbsp' + j + "=" + '&nbsp' + i*j + '&nbsp&nbsp&nbsp' + '</td>');
                        }else{
                            document.write('<td class="line">' + '<p style="color:blue;">' + i + "*" + '&nbsp' + j + "=" + '&nbsp' + i*j + '&nbsp&nbsp&nbsp' + '</td>');   
                        }
                        
                    }
                }
                document.write('</tr>');
            </script>
            
            
        </table>
       </body>
      <html>

 

반응형