<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
    document.write("<table>");
    for (var x = 1; x <= 9; x++) {
        document.write("<tr>");
        for (var j = 1; j <= x; j++) {
            document.write("<th>" + y + "*" + x + "=" + y * x + "</th>");
        }
        document.write("</tr>");
    }
    document.write("</table>");
    </script>
</body>
</html

解决方案 »

  1.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
        document.write("<table>");
        for (var x = 1; x <= 9; x++) {
            document.write("<tr>");
            for (var j = 1; j <= x; j++) {
                document.write("<th>" + y + "*" + x + "=" + y * x + "</th>");
            }
            document.write("</tr>");
        }
        document.write("</table>");
        </script>
    </body>
    </html
      

  2.   

    我先不管你逻辑对不对 但是有个问题你要清楚
    document.write 这玩意你每执行一次 dom就重绘一次 也就是清空<body></body>中的内容然后输出当前内容 所以你要使用个str 拼接上你的html内容 一次性写进去eg:
    var str="<table>"
        str +="<tr>....</tr>"
    document.write(str);
      

  3.   


    谢谢  那为什么我改成这样也打不出来
            var s = "<table>";
            for (var x = 1; x <= 9; x++) {
                s += "<tr>";
                for (var j = 1; j <= x; j++) {
                    s += "<th>" + y + "*" + x + "=" + y * x + "</th>";
                }
                s += "</tr>";
            }
            s += "</table>";
            document.write(s);
      

  4.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title></title>
    </head>
    <body>
     <table >
      <script type="text/javascript">
      for (var x = 1; x <= 9; x++) {
      document.write("<tr>");
      for (var j = 1; j <= x; j++) {
      document.write("<td>" + j + "*" + x + "=" + j * x + "</td>");
      }
      document.write("</tr>");
      }
      document.write("</table>");
      </script>
    </body>
    </html>Y是哪里来的?是J吧~!另外,那个是 TH?TD吧
      

  5.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title></title>
    </head>
    <body>
     <table >
      <script type="text/javascript">
      for (var x = 1; x <= 9; x++) {
      document.write("<tr>");
      for (var j = 1; j <= x; j++) {
      document.write("<td>" + j + "*" + x + "=" + j * x + "</td>");
      }
      document.write("</tr>");
      }
      document.write("</table>");
      </script>
    </body>
    </html>
      

  6.   


    <script type="text/javascript">
    document.write("<table style='background:green;'>");
    for (var x = 1; x <= 9; x++) {
    document.write("<tr>");
    for (var y = 1; y <= x; y++) {
    document.write("<td style='background:yellow;'> " + y + "*" + x + "=" + y * x + " </td><td> </td>");
    }
    document.write("</tr>");
    }
    document.write("</table>");
    </script>
      

  7.   

    只是用错了变量!

    for (var j = 1; j <= x; j++) {
    改为
    for (var y = 1; y <= x; y++) {
    即可