D0n9X1n / hexo-blog-encrypt

Yet, just another hexo plugin for security.
https://www.npmjs.com/package/hexo-blog-encrypt
MIT License
989 stars 102 forks source link

JS文件报错 #78

Closed hubelief closed 5 years ago

hubelief commented 5 years ago

密码输入后按Enter没有正常响应,页面的JS报错: ReferenceError:$ is not defined blog-encrypt.js

D0n9X1n commented 5 years ago

See https://github.com/MikeCoder/hexo-blog-encrypt/issues/72

hubelief commented 5 years ago

还是没有解决该问题,依旧是不响应,报的一样的错。 我使用的是next主题;JQuery地址也没有错.... 设置的模板信息:

title: Hello World
password: Mike
abstract: Welcome to my blog, enter password to read.
message: Please enter the password to read.
template:
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id="hbe-security">
    <div class="hbe-input-container">
    <input type="password" class="hbe-form-control" id="pass" placeholder="{{message}}" />
        <label for="pass">{{message}}</label>
        <div class="bottom-line"></div>
    </div>
    </div>
    <div id="decryptionError" style="display:none;">{{decryptionError}}</div>
    <div id="noContentError" style="display:none;">{{noContentError}}</div>
    <div id="encrypt-blog" style="display:none">
    {{content}}
    </div>
D0n9X1n commented 5 years ago

使用 hexo-blog-encrypt v2.0.11 测试 next v5.1.0 和 next v7.0.1 均未发现问题。

测试地址:https://mhexo.github.io/example-site/2018/06/25/encrypt-test/

请仔细看 console 上下文,确定问题点。

hubelief commented 5 years ago

环境:hexo-theme-next:5.1.4,hexo-blog-encrypt ^2.0.11

console信息:

ReferenceError: $ is not defined[详细了解]        blog-encrypt.js:114:1
<anonymous> http://localhost:4000/lib/blog-encrypt.js:114 

unreachable code after return statement[详细了解] core_e56a9d5fac6bf7d90bbf65553497278f.js:94:13352

unreachable code after return statement[详细了解] core_e56a9d5fac6bf7d90bbf65553497278f.js:133:212254

                                                 watchman.min.js:181:29

getElementById() 被传递了空字符串参数。            watchman.min.js:94:31
D0n9X1n commented 5 years ago

原因是 jquery 没有被加载,可能是浏览器禁用了外部的 js 文件,也可能是防广告插件拦截了外部的 js 文件。换一个浏览器试试。如果还是不行,你可以添加一个 jquery 到模版里面,直接从本地加载。

hubelief commented 5 years ago

没有禁用外部的js文件,也没有添加防广告插件。

hubelief commented 5 years ago

找到错误,原因是使用使用hexo generator编译后,template内的Script没有正常的被解析加载。 解决: 在\themes\next\layout_partials\head\custom-head.swig中引入JQuery的CNDJS即可。 麻烦您了,非常感谢。