forked from jiansenc/tiktok_barrage_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ak.html
57 lines (51 loc) · 1.3 KB
/
ak.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<title>上传txt文件并读取第32行内容</title>
<meta charset="utf-8">
<script>
var arr = [];
function readContent(file) {
var reader = new FileReader();
reader.onload = function (e) {
var lines = e.target.result.split('\n');
var line32 = lines[31].match(/[0-9]+(\.[0-9]+)?/g);
if (line32 != null) {
for (var i = 0; i < line32.length; i++) {
arr.push(parseFloat(line32[i]));
}
}
updateNumberList();
};
reader.readAsText(file);
}
function handleFiles() {
var files = document.getElementById("fileUpload").files;
for (var i = 0; i < files.length; i++) {
if (files[i].type === "text/plain") {
readContent(files[i]);
} else {
alert("请选择txt文件");
}
}
}
function updateNumberList() {
var numberList = document.getElementById("numberList");
numberList.innerHTML = "";
for (var i = 0; i < arr.length; i++) {
var li = document.createElement("li");
li.innerText = arr[i];
numberList.appendChild(li);
}
}
</script>
</head>
<body>
<input type="file" id="fileUpload" multiple onchange="handleFiles()">
<p>已读取的数字:</p>
<ul id="numberList"></ul>
<script>
updateNumberList();
</script>
</body>
</html>