gpt4 book ai didi

javascript - jQuery 3.2.1,自动数字插件(最新) 'Uncaught SyntaxError: Unexpected token export'

转载 作者:行者123 更新时间:2023-11-29 19:03:43 26 4
gpt4 key购买 nike

我试图让 autoNumeric jQuery 插件为美元输入格式工作,但该文件在 Linux 上最新版本的 Chrome 的第 5450 行引发“未捕获语法错误:意外 token 导出”。

我在 jQuery 之后这样调用它:

  <!-- jQuery 3.2.1 from CDN -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- autoNumeric for USD formatting -->
<script src="js/autoNumeric.js" type=text/javascript></script>

所以我猜这一定是文件中的错误?它声明该插件与网站上的 jQuery 1.7.2 或更高版本兼容,所以我不确定这里的问题是什么。有没有人遇到过这样的事情?

最佳答案

它失败了,因为你正在尝试使用 AutoNumeric 的非编译版本,它是用 ES6 作为模块编写的,而浏览器本身仍然不支持它(它们都不理解 import/export 语句)。

因此,为了在浏览器中使用 AutoNumeric(即 https://github.com/autoNumeric/autoNumeric/tree/next#in-the-browser),您需要导入 dist/ 文件夹中的已编译版本(即. dist/autoNumeric.min.js),或者只使用 CDN。

注意 1:为了能够使用最新的 Web 技术,AutoNumeric 使用 babel + webpack 将模块编译成一个单一的“放入网页即可运行”文件。

注意 2:AutoNumeric 已经放弃了几个月的 jQuery 依赖,试试吧! ;)

关于javascript - jQuery 3.2.1,自动数字插件(最新) 'Uncaught SyntaxError: Unexpected token export',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com