【发布时间】:2009-12-20 22:58:29
【问题描述】:
我在服务器 (C#) 上有一个循环来执行此操作:
for(i=0;i<=Request.Files.Count - 1; i++)
{
// tell the client that the upload is about to happen
// and report useful information
Update(percent, message, i, 0);
System.Threading.Thread.Sleep(1000);
// tell the client that upload succeeded
// and report useful information
Update(percent, message, i, 1);
}
函数“Update”写入客户端 JavaScript 函数“PublishUpdate”。 row 参数是表中包含上传文件的行。 “状态”告诉我们文件是即将上传 (0) 还是即将完成 (1)。
问题是我似乎无法正确计数。循环似乎 在表中开始 2 或 3 行,或者(在使用行值之后)它在 最后一行。我对 jQuery 很陌生。在你看来,有什么明显的错误吗?
function PublishUpdate(percent, message, row, status)
{
var bodyRows = $("#picTableDisplay tbody tr");
bodyRows.each(function(index){
if (index == row && status == 0)
$('#status'+index).html("<img alt='inproc' src='images/loading.gif' />");
else if (index == row && status == 1)
$('#status'+index).html("complete");
});
}
最后,表格是这样的:
<table width="100%" cellspacing="0" cellpadding="3" border="0" align="center" id="picTableDisplay" summary="" class="x-pinfo-table">
<tbody id="files_list" class="scrollContent">
<tr class="evenRow">
<td class="numCol" id="num0">
</td>
<td class="fnameCol" id="fname0">
</td>
<td class="statusCol" nowrap="" id="status0">
</td>
<td class="remCol" id="rem0">
</td>
</tr>
<tr class="oddRow">
<td class="numCol" id="num1">
</td>
<td class="fnameCol" id="fname1">
</td>
<td class="statusCol" nowrap="" id="status1">
</td>
<td class="remCol" id="rem1">
</td>
</tr>
<tr class="evenRow">
<td class="numCol" id="num2">
</td>
<td class="fnameCol" id="fname2">
</td>
<td class="statusCol" nowrap="" id="status2">
</td>
<td class="remCol" id="rem2">
</td>
</tr>
AND SO ON ...
提前致谢。
【问题讨论】:
-
为什么大括号后面有
);? -
是的,对不起。我剪切并粘贴并错过了“}”。已完成更新,谢谢。
-
如果你真的想使用 ID 而不仅仅是行号,给行本身一个 ID 然后将单元格称为 $('#row2 .fnameCol') 或其他什么会更干净。