1

我只是想创建一个简单的 javascript 函数来输出一个小表,但似乎无法让它工作。

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

        function drawTable()
        {
            var tableDiv = document.getElementById( "numbersTable" );

            tableDiv.innerHTML = "<table>" + 
            "<caption>Numbers Table</caption>" +
            "<thead><th>Number</th><th>Square</th><th>Cube</th></thead>" +
            "<tbody><tr><td>1</td><td>2</td><td>3</td></tr>" +
            "</tbody></table>";
        }

    </script>
</head>
<body>
<div id = "numbersTable"></div>
</body>

谁能看出问题出在哪里?

4

1 回答 1

3
  1. 你不打电话drawTable()
  2. 记得在之后调用它<div id="numbersTable"></div>
于 2013-02-10T21:31:16.247 回答