我有一个带有空表的HTML div部分:
<div id="report_result" class="container">
<table cellpadding="0" cellspacing="0" border="0" class="dataTable" id="example">
</table>
</div>
现在我动态创建表头和正文,它基于在页面中使用的params:
function runreport(datastring)
{
var tables_header = $('<thead><tr><th>Flow State</th><th>Flow Logging Id</th><th>Co-relation Id</th></tr></thead><tbody></tbody>');
('#example').empty(); // added later
tables_header.appendTo('#example');
}
有一个“运行报告”按钮,点击调用'runreport'功能,用户选择了选项。
第一次表格很好但如果用户只是重新点击“运行报告”按钮,表格的内容就会重复,等等。因此,每次单击时都会添加表头。
因此我在创建相同内容之前删除了所有表格的标题,行,页脚等:
但即使在第一时间我也收到错误:
"#example".empty is not a function
[Break On This Error]
('#example').empty();
但http://api.jquery.com/empty/说明了这种方法 - 那么为什么我会收到此错误?
答案 0 :(得分:3)
您忘记了括号前面的$
:
$('#example')...