相较于JS,jquery语法更简单,所以能用jquery的我都会选择使用jquery
近期做了关于油猴插件使用的项目,油猴脚本使用jquery时遇到的一个问题,下面分享给大家。
如果脚本依赖其他js库的话,可以使用require指令,在运行脚本之前先加载其他库,常见用法是加载jquery
// @require https://code.jquery.com/jquery-2.1.4.min.js
问题:
引入jquery后报错提示 eslint:no-undef - '$' is not defined
网友给出的解决办法是在引入jquery是添加下面注释,结果如下图报错:eslint:userscripts/no-invalid-metadata Code found between in metadata
/* globals jQuery, $, waitForKeyElements */
解决方案:
将/* globals jQuery, $, waitForKeyElements */放到下面脚本函数中就可以了
以上是我的解决方案,供大家参考