我正在用我得到的json响应动态显示表。
我面临的问题是,该表正在显示数据以及下面的
<section class="widget">
<div>
<table id="1d" class="losstable tablesorter">
<thead>
<tr>
<th>Symbol</th>
<th>Close</th>
<th>Change(Rs)</th>
<th>Change(%)</th>
<th>AS ON</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="1w" class="losstable tablesorter">
<thead>
<tr>
<th>Symbol</th>
<th>Close</th>
<th>Change(Rs)</th>
<th>Change(%)</th>
<th>AS ON</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="2w" class="losstable tablesorter">
<thead>
<tr>
<th>Symbol</th>
<th>Close</th>
<th>Change(Rs)</th>
<th>Change(%)</th>
<th>AS ON</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="3w" class="losstable tablesorter">
<thead>
<tr>
<th>Symbol</th>
<th>Close</th>
<th>Change(Rs)</th>
<th>Change(%)</th>
<th>AS ON</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="1m" class="losstable tablesorter">
<thead>
<tr>
<th>Symbol</th>
<th>Close</th>
<th>Change(Rs)</th>
<th>Change(%)</th>
<th>AS ON</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</section>
这是我的代码
{{1}}
这是小提琴
http://jsfiddle.net/abkNM/7607/
你能告诉我如何解决这个问题吗?
答案 0 :(得分:2)
<script type="text/javascript">
var tableclass = ".tablesorter";
var html = "";
for (var s = 0; s < jsonresp.length; s++)
{
var symbol = jsonresp[s].symbol,
close = jsonresp[s].todays_close,
prev_close = jsonresp[s].prev_close,
as_on = "YDA";
d = parseFloat(close) - parseFloat(prev_close), d = d.toFixed(2);
var l = (close - prev_close) / close * 100;
l = l.toFixed(2), html += "<tr><td>" + symbol + "</td><td>" + close + '</td><td class="redclass">' + d + '</td><td class="redclass">' + l + '</td><td class="">' + prev_close + "(" + as_on + ")</td></tr>";
}
$(".widget > div > table > tbody").html(html);
</script>
答案 1 :(得分:1)
查看你的jsfiddle,你有不同的id表,但你只选择第一个id为#1d
的表,并将数据附加到第一个表的tbody。其他表格标题仍在打印中。
在你的jsfiddle中你有var tableid = "#1d";
但是之后没有任何事情发生在你的插入html的调用之外。看起来你的代码还没有完成/完成。