如何使用javasacript在文本框中阅读和显示文本文件值 [英] How to read and display text file value in text box using javasacript

查看:78
本文介绍了如何使用javasacript在文本框中阅读和显示文本文件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想

read and display text file value in text box using Javasacript



这是我的代码是正确的但是值不显示在文本框中请给我解决方案。



我尝试过:




Here is my code code is correct but value is not display in textbox please give me solution.

What I have tried:

  <div id="page-wrapper">
      
      <input type="text" id="allText">

    </div>

<script>
    var allText = document.getElementById('allText');
function readTextFile(file) {
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function () {
        if (rawFile.readyState === 4) {
            if (rawFile.status === 200 || rawFile.status == 0) {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
}
readTextFile("file:///C:/MACID.txt");

</script>

推荐答案

Quote:

readTextFile("file:///C:/MACID.txt");



出于安全原因,JavaScript和WebApps无法直接访问用户文件系统。

读取本地文件的唯一方法是通过打开文件对话框和用户批准。


JavaScript and WebApps do not have direct access to user file system for security reasons.
The only way to read a local file is through 'open file' dialog and with user approval.


这篇关于如何使用javasacript在文本框中阅读和显示文本文件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆