html能否读txt文本文件的数据?
请教大家一个问题,html能否读txt文本文件的数据?能否举个例子?
以下是引用gupiao175在2011-1-8 23:06:12的发言:
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
var xmlUrl = new ActiveXObject('Microsoft.XMLHTTP');
xmlUrl.Open('GET','a255.txt');
xmlUrl.Send();
document.write(bytes2BSTR(xmlUrl.ResponseBody));
setTimeout('alert(bytes2BSTR(xmlUrl.ResponseBody))',2000);
把a255.txt改为你要看的txt试下!
2楼的大虾,这段代码我也看过,那么我还想请教一下能否用这段代码实现定时读取例子中a255.txt文件呢?如每隔5秒读取a255.txt文件中的内容,
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
var xmlUrl = new ActiveXObject('Microsoft.XMLHTTP');
xmlUrl.Open('GET','a255.txt');
xmlUrl.Send();
document.write(bytes2BSTR(xmlUrl.ResponseBody));
setTimeout('alert(bytes2BSTR(xmlUrl.ResponseBody))',2000);
把a255.txt改为你要看的txt试下!