FileSaver 什么都不做

FileSaver does nothing

下面的代码有什么不对download/save?

https://jsfiddle.net/36nuqrqm/

function save_file()
{
 var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
 saveAs(blob, "hello world.txt");
}
<script src="https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.js"></script>

aaa
<button id="b" onclick="save_file()">export to CSV</button>
bbb

我正在使用 file saver

here是其工作代码的示例

在 Frameworks & Extensions 中使用 No wrap - in not onLoad 为此。

使用 onLoad 的结果:

<script type="text/javascript">//<![CDATA[
window.addEvent('load', function() {
function save_file()
{
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
}
});//]]> 

</script>

使用不换行的结果:

<script type="text/javascript">//<![CDATA[

function save_file()
{
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
}
//]]> 

</script>

或者更好,将 jquery 与 onLoad 一起使用 https://jsfiddle.net/36nuqrqm/2/

<button id="export_to_csv">export to CSV</button>

$("#export_to_csv").on('click', function (){
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
})