• 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>
  • 相关阅读:
    Spark官方文档——本地编写并运行scala程序
    scala函数组合器
    scala数组
    scala实现kmeans算法
    Nginx 服务器安装及配置文件详解
    OpenVAS开源风险评估系统部署方案
    Elasticsearch和Head插件安装
    手把手教你在CentOS 7.4下搭建Zabbix监控(转)
    elasticsearch6.X 及head插件部署(完整版)
    Vim配置(python版)
  • 原文地址:https://www.cnblogs.com/qq450867541/p/13259625.html
Copyright © 2020-2023  润新知