gpt4 book ai didi

javascript - Medium.js 不工作 - 'Medium is not defined'

转载 作者:行者123 更新时间:2023-12-01 04:05:48 25 4
gpt4 key购买 nike

根据author ,像这样:

<html>
<head>
<!-- JS for Medium -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-core.min.js" defer></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-classapplier.min.js" defer></script>
<script type="text/javascript" src="https://cdn.rawgit.com/jzaefferer/undo/master/undo.js" defer></script>
<script type="text/javascript" src="https://cdn.rawgit.com/jakiestfu/Medium.js/master/medium.min.js" defer></script>
<!-- CSS for Medium -->
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/jakiestfu/Medium.js/master/medium.css"/>
</head>
<body>

<div id="editor"></div>

<script>
new Medium({
element: document.getElementById('editor')
});
</script>
</body>
</html>

应该可以完美工作,但我不断得到

Uncaught ReferenceError: Medium is not defined - Line 16

我在这里做错了什么吗?我花了过去 2 个小时来解决这个问题,但没有成功......

谢谢。

最佳答案

defer 属性设置脚本在页面加载后最后运行。因此,代码在加载 Medium.js 之前运行。有两种可能的解决方案。您可以删除该属性以立即加载库及其组件。或者当整个页面包含脚本时添加事件监听器:

window.onload = function(){
new Medium({
element: document.getElementById('editor')
});
}

关于javascript - Medium.js 不工作 - 'Medium is not defined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41836595/

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