首页 > Web开发 > 详细

【乘法表】innerHTML可以将字符串标签转为html标签

时间:2018-07-26 22:40:46      阅读:151      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

</head>
<body>
  <script>
    var body = document.body;
    var table = document.createElement(‘table‘);
    table.setAttribute("border", 1);
    var trs = ‘‘;

    for(var i = 1; i < 10; i++) {
      var tds = ‘‘;
      for(var j=1; j <= i; j++) {
          tds += ‘<td>‘ + i + ‘*‘ + j + ‘=‘ + i * j +‘</td>‘;
      }
      trs += ‘<tr>‘ + tds + ‘</tr>‘;
    }
    table.innerHTML = trs;
    body.append(table);
  </script>
</body>
</html>

  

法二:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>99乘法表</title> 
<script type="text/javascript"> 
    document.write("<center><table border=\"3\">"); 
      for (i = 1; i <= 9; i++) { 
        document.write("<tr>"); 
        for (j = 1; j <= 9; j++) { 
          if (j <= i) { 
              document.write("<td>" + i + "*" + j + "=" + i * j + "</td>") 
          } else {
              document.write("<td> </td>"); 
          } 
        }
        document.write("</tr>"); 
      } 
    document.write("</table></center>"); 
</script> 
</head> 
<body> 
</body> 
</html>

 

【乘法表】innerHTML可以将字符串标签转为html标签

原文:https://www.cnblogs.com/oklfx/p/9374668.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!