javascript - 如何将表格附加到DIV

标签 javascript jquery html

我正在尝试将表格附加到 div:

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            function addStuff() {
                var html = '<table>';
                $.each(function() {
                        html += '<tr><td>' + '</td></tr>';
                        });
                html += '</table>';
                $("#divResults").append(html);

            }
        </script>
    </head>
    <body>
        <div id="divResults"></div>
        <button onclick="addStuff()">Add Stuff</button>
    </body>
</html>

但它不起作用。我想将表格动态添加到 DIV block 。

最佳答案

你想将表格附加到 DIV 试试这个....

    <html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">

    function addTable() 

{
    $('#divResults').append('<table width="320" border="1"><tr><td colspan="2" rowspan="1">' + " wdw" + '</td></tr><tr><td width="118">' + "sxs" + '</td><td width="186">' + "xs" + '</td></tr></table>');
}

    </script>
        </head>
    <body>
    <div id="divResults">
    </div>
    <button onclick="addTable()">Add Stuff</button>
    </body>
    </html>

关于javascript - 如何将表格附加到DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16341681/

相关文章:

javascript - 云错误 : must supply api-key -/node_modules/cloudinary/lib/utils. js:982

javascript - Firefox javascript 在 ajax 回调结果中重定向导致白屏

javascript - for 循环内的范围

html - CSS:将图标悬停在图片/视频div顶部

javascript - Sequelize 类型错误 : Cannot read property 'max' of undefined

jquery - 如何找到元素(div)底部的像素值

jQuery 获取 XML 中的匹配节点

javascript - 如何获取 HTML 中的文本和 href 值,然后将它们设置为 JQuery UI 自动完成中的值和标签

html - 如何确保没有其他文本与我的标题标签在同一行?

php - 使用 PHP 将 HTML 表单数据转换为 PDF 文件