<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        function downloadFile(fileName, content){

            var aLink = document.createElement('a');
            var blob = new Blob([content]);
            //var evt = document.createEvent("HTMLEvents");firefox不支持
            var evt = document.createEvent("MouseEvents"); //firefox、chrome都支持
            aLink.download = fileName;
            aLink.href = URL.createObjectURL(blob);
            aLink.textContent = "Download Hello World!";
            //evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, aLink);//网友提出的方法不可行
            evt.initEvent("click", true, true);//initEvent 不加后两个参数在FF下会报错


            document.body.appendChild(aLink);

            aLink.dispatchEvent(evt);
        }
    </script>
</head>
<body>
    <input type="button" onclick="downloadFile('1.txt','hello world!')" />
</body>
</html>