如果你做得太早,你会得到错误Uncaught ReferenceError: filepicker is not defined
。
我正在使用来自https://developers.filepicker.io/docs/web/的代码来加载它:
For advanced users, if you want to load the javascript in a non-blocking fashion, you can use this instead:
<script type="text/javascript">
(function(a){if(window.filepicker){return}var b=a.createElement("script");b.type="text/javascript";b.async=!0;b.src=("https:"===a.location.protocol?"https:":"http:")+"//api.filepicker.io/v1/filepicker.js";var c=a.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c);var d={};d._queue=[];var e="pick,pickMultiple,pickAndStore,read,write,writeUrl,export,convert,store,storeUrl,remove,stat,setKey,constructWidget,makeDropPane".split(",");var f=function(a,b){return function(){b.push([a,arguments])}};for(var g=0;g<e.length;g++){d[e[g]]=f(e[g],d._queue)}window.filepicker=d})(document);
</script>
我不知道如何知道它何时加载,以便我可以调用 filepicker.setKey()。一种解决方法是每次我使用文件选择器时都调用它,但这似乎很蹩脚。