JQuery如何将表格单元格添加到表格行

时间:2014-06-26 23:36:35

标签: javascript jquery html-table

我试图使用jQuery动态地将单元格添加到我的表格行。

HTML:

<table class="col-md-12" id="location-table">
    <tr id="location-row">
        <td>
            <label>
                <input type="radio" id="location-radio"  value="other" />
                Other location
            </label>
        </td>
    </tr>
</table>

JS / JQuery(我已尝试过这两种方法):

$('<td><label><input type="radio" id="location-radio" value="test" />Test</label></td>').appendTo('#location-row');

$('#location-row').append('<td><label><input type="radio" id="location-radio" value="test" />Test</label></td>');

非常感谢所有帮助。

2 个答案:

答案 0 :(得分:2)

您的代码应该有效..

$('<td><label><input type="radio" id="location-radio" value="test" />Test</label></td>').appendTo('#location-row');

$('#location-row').append('<td><label><input type="radio" id="location-radio" value="test" />Test</label></td>');

这不是最优雅的解决方案,但两者都适用于jsfiddle ...

http://jsfiddle.net/d5AdX/

你正确加载jquery吗?

答案 1 :(得分:0)

如果您在网站上打开chrome dev控制台并提交美元符号($),它应该告诉您它是一个功能。如果在右边,它没有链接到带有行号的js文件(类似于&#39; jquery.min.js:2&#39;),那么jquery不会在你的页面上加载你需要确保你的头像是正确的。

这是指向google cdn的链接,您可以在其中找到所有jquery脚本: https://developers.google.com/speed/libraries/devguide#jquery

相关问题