我得到的文本文件包含内容,例如一行: 764#00:03:12.037300#00:04:12.123000
然后我想在表格中显示。我知道如何使用 jQuery
将其显示到表中,如下所示:
JQUERY
$("#upload").click(function() {
if (($("#fileUpload").val())) {
if (typeof (FileReader) != "undefined") {
var reader = new FileReader();
reader.onload = function (e) {
var rows = e.target.result.split("\n");
for (var i = 0; i < rows.length; i++) {
var row = $("<tr />");
var cells = rows[i].split("#");
for (var j = 0; j < cells.length; j++) {
var cell = $("<td />");
cell.html(cells[j]);
row.append(cell);
}
$('#sampleTbl tbody').append(row);
}
}
reader.readAsText($("#fileUpload")[0].files[0]);
} else {
alert("This browser does not support HTML5.");
}
} else {
alert("Please upload a valid CSV file.");
}
});
而且,这是我的 html 表格:
<table id="sampleTbl", class="table table-striped table-bordered">
<thead>
<th>BIB</th>
<th>Time Start</th>
<th>Time End</th>
<th>Time</th>
</thead>
<tbody></tbody>
</table>
但我不知道如何计算时间结束
减去时间开始
的结果,然后可以在时间
列中显示附加表。怎样才能这样给予呢?请有人帮忙
最佳答案
var
startstring = "00:03:12.037300",
endstring = "00:04:12.123000",
startarray = (startstring.replace(".",":")).split(":"),
endarray = (endstring.replace(".",":")).split(":"),
starttime = new Date(2000,1,1,startarray[0],startarray[1],startarray[2],Math.floor(startarray[3]/1000)),
endtime = new Date(2000,1,1,endarray[0],endarray[1],endarray[2],Math.floor(endarray[3]/1000)),
time = new Date (endtime - starttime),
timestring = time.getHours()-1+":"+time.getMinutes()+":"+time.getSeconds()+"."+time.getMilliseconds();
alert(timestring);// Just for testing
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date
关于javascript - JQuery读取、解析、显示文本文件并统计结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33821011/