将简单的html表集成到javascript中

时间:2012-07-26 20:03:16

标签: javascript html

我被要求使用javascript创建一个表格,显示用户给我的变量的简单算术,我确信我的语法在我的document.write中是关闭的,但我不知道在哪里如何。我的错误控制台说我错过了第18行的结束')'结束,这根本不是真的。我看到在其他情况下,为此目的使用document.write函数是不受欢迎的,但是我明确表示我应该这样做,作为完成本实验的要求的一部分,所以我真诚地为这次违规道歉

代码如下 - 提前感谢任何和所有帮助:

<script>  
     var  e1="", e2="", e3="", e4="", e5="", e6="", e7="", e8="", e9="";

    e1 = prompt("Enter your first name in lower case", "");
    var e1u = substr(0, 1);
    e1 = e1u.toUpperCase() + e1.substr(1, e1.length-1);
    e2 = prompt(e1 + ", enter an integer from 1 to 9", "");
    e3 = prompt("Now enter 5 numbers delineated by a comma!", "");
    e4 = prompt("Now enter 3 colors delineated by a comma!");
    e5 = new date();
    e6 = e3.split(',');
    e7 = e4.split(',');
    document.write(""Today's Date = " + e5.getMonth()+1 + "/" + e5.getDay() +
    "/" + e5.getFullYear() + "\n" + "The number in e2 is " + e2 + "\n"
    + "<table><caption>Times Table for the number + e2 + "</caption>"");
    for(var i=0; i<13; i++)
    {
            document.write(""<tr>""<td>" + e2 + "</td>" + "<td>" + i + "</td>" + "<td>" + "=" + "</td>" + "<td>" + (e2 * 1) * i + "</td>""</tr>"");
    }               


</script>

4 个答案:

答案 0 :(得分:3)

我为你修好了以下内容:

document.write("Today's Date = " + e5.getMonth()+1 + "/" + e5.getDay() +
"/" + e5.getFullYear() + "\n" + "The number in e2 is " + e2 + "\n"
+ "<table><caption>Times Table for the number" + e2 + "</caption>");

document.write("<tr><td>" + e2 + "</td>" + "<td>" + i + "</td>" + "<td>" + "=" + "</td>" + "<td>" + (e2 * 1) * i + "</td></tr>");

不要加倍引用,并使用语法高亮度的编辑器。它会为你节省很多时间。

答案 1 :(得分:0)

这看起来不对:

+ "</td>""</tr>""

也许你想要

+ "</td></tr>"

答案 2 :(得分:0)

日期(),而不是日期()

e1.substr,而不仅仅是substr,我会使用substring,而不是substr

在号码e2之后缺少引号

我会这样做 http://jsfiddle.net/mplungjan/eggWj/

答案 3 :(得分:-1)

表必须具有以下嵌套结构:

<table>
   <tr>
       <td> ... </td>
   </tr>
</table>

您的<caption>无法放置在原来的位置,可能完全属于道明或桌面之外。