zoukankan      html  css  js  c++  java
  • HTML5

    1、js导出为txt/doc格式文件

    <body>
        文件名称:
        <input id="fileName">
        <br>
        文本内容:
        <textarea id="textContent" cols="30" rows="10"></textarea>
        <br>
        <button type="button" onclick='SaveTxt()'>保存</button>
    </body>
    <script type="text/javascript">
        function SaveTxt() {
            var FileName = document.getElementById('fileName').value + '.txt'; // 文件名称 - 文件名称后添加“.txt”或“.doc”可以保存为对应格式
            var Content = document.getElementById('textContent').value; // 文本内容
    
            var element = document.createElement('a');
            element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(Content));
            element.setAttribute('download', FileName);
            element.style.display = 'none';
            document.body.appendChild(element);
            element.click();
            document.body.removeChild(element);
        }
    </script>

     js导入数据

    <body>
        <button type="button" onclick='ImportScheme()'>导入方案</button>
    </body>
    <script type="text/javascript">
        function ImportScheme() {
            var file = $('<input type="file" />');
            // 选择好文件后,获取选择的内容
            file.change(function (e) {
                openFile(e);
            })
            file.click();
        }
    
        function openFile(e) {
            var input = e.target;
            var reader = new FileReader();
            reader.onload = function () {
                if (reader.result) {
                    console.log(reader.result);
                }
            };
            reader.readAsText(input.files[0]);
        }
    </script>
  • 相关阅读:
    中芯国际唐镇生活园区二期奠基 助力员工安居乐业
    权限管理架构
    不登录电脑启动程序
    Nagios 系统监控
    JieBaNet+Lucene.Net
    FontAwesome 图标
    Net多线程编程
    Scala Control Structures
    OAuthLogin2.0
    Telnet服务器和客户端请求处理
  • 原文地址:https://www.cnblogs.com/qq450867541/p/13259625.html
Copyright © 2011-2022 走看看