我正在尝试创建一个脚本,用于在桌面(aspx页)中打开本地文件。该脚本读取文件并提取元素的ID(例如:textbox,button,...)并将其存储在列表中。问题是我希望此脚本从给定的URL中打开文件,而不是从代码中显示的输入type =“ file”中打开文件。谢谢您对我的帮助。
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="readfile.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<h5>Select a Text File</h5>
<input type="file" onchange="loadText(event)">
<script>
function loadText(event) {
let file = event.target.files[0];
// Read file content as text
let reader = new FileReader()
reader.readAsText(file)
reader.addEventListener('load', function (event) {
let text = event.target.result;
var taille = text.length;
var i = 0;
var List = new Array();
var k = 0;
while (i < taille){
var ch = "";
var ide = text[i] + text[i + 1];
var j = 0;
if (ide == "ID") {
j = i + 4;
do {
ch = ch + text[j];
j++;
} while (text[j] != '"');
List[k] = ch;
k++;
i = j;
}
else {
i++;
}
}
for (i = 0; i < k; i++) {
alert ("id N°"+i+" "+List[i]);
}
})
}
</script>
</body>
</html>