Skip to content

Instantly share code, notes, and snippets.

@jikeytang
Created July 7, 2014 23:24
Show Gist options
  • Save jikeytang/bc8a4f78d2491f2343bf to your computer and use it in GitHub Desktop.
Save jikeytang/bc8a4f78d2491f2343bf to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140708-题目1
用速度最优的代码输出一个带有细线表格的乘法口诀表。
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
@ljkfgh2008
Copy link

//没有楼上2位的好 凑个热闹
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>jsTest</title>
   <style>table{border-collapse:collapse}</style>
</head>
<body>
    <table id="table1"  border="1"></table>
      <script>
        var data = new Array();
        for (var i = 1; i <= 9; i++) {
            data.push('<tr>');
            for (j = 1; j <= i; j++) {
                data.push('<td>' + i + 'X' + j + '=' + i * j + '</td>');
            }
            data.push('</tr>');
        }
        data.push('</tbody><table>');
        document.getElementById('table1').innerHTML = data.join('');
    </script>
</body>
</html>

@ysgcreate
Copy link

<!DOCTYPE html>
<html>
<head>
    <title>Document</title>
    <meta charset='utf-8'>
    <style>
        #result span {
            border: solid 1px #eeeeee;
            margin: 2px;
            padding: 2px;
            line-height: 30px;
        }
    </style>
</head>
    <body>
        <div id="result"> </div>
        <script>
            var res=' ';
            for (var i=1;i<=9;i++) {
                for (var j=1;j<=i;j++) {
                    res += '<span>'+j+'*'+i+'='+(i*j)+'</span>';
                    if (i==4&&j==2) {
                        res+=' ';
                    }
                }
                res += '<br/>';
            }
            document.getElementById('result').innerHTML=res;
        </script>
    </body>
</html>

第4行第2列时对不齐,所以加了个空格

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment