【发布时间】:2017-03-09 06:01:34
【问题描述】:
以上代码使用JSON输出生成HTML表格。
但是,我的问题是,在这个JQuery 运行之后,其他页面内容没有显示。
<script>
$(document).ready(function () {
var html = '<table class="table table-striped">';
html += '<tr>';
var flag = 0;
var data2 = <?php echo $data; ?>;
$.each(data2[0], function(index, value){
html += '<th>'+index+'</th>';
});
html += '</tr>';
$.each(data2, function(index, value){
html += '<tr>';
$.each(value, function(index2, value2){
html += '<td>'+value2+'</td>';
});
html += '<tr>';
});
html += '</table>';
$('body').html(html);
console.log(html);
});
</script>
当页面加载时,内容应该消失并且它应该只显示特定的表格。
【问题讨论】:
-
那是因为你基本上是把你body的所有内容都替换到这个表中,看你的代码$('body').html(html)。
-
你提到了这个,
content should disappear and it should shows particular table only。根据您所提到的,您的代码正在做完全相同的事情。它将正文中的所有内容(即页面中的 Everything)替换为您在此脚本中构建的表格!现在有什么问题? -
@PrashanthBenny 好的,那么我需要做什么,如何生成包含其他表格内容的表格
-
您可以将新表附加到您已有的表中!
标签: javascript php jquery html json