gpt4 book ai didi

Javascript引用错误: TL not defined even though it's explicity defined in *. js文件

转载 作者:行者123 更新时间:2023-11-27 23:50:56 32 4
gpt4 key购买 nike

我正在尝试按照 these instructions 使用 Knight Laboratories 的 Timeline JS 工具的本地实现。 。因为我的用例需要在 R 或 Python 中动态开发 JSON,所以我尝试自己编写 html 文件。我目前的代码如下:

html <- paste('<!DOCTYPE html><html><head><link title="timeline-styles", rel="stylesheet" href="//cdn.knightlab.com/libs/timeline3/latest/css/timeline.css"></head><body><script src="//cdn.knightlab.com/libs/timeline3/latest/js/timeline.js"></script><div id="timeline-embed" style="width: 100%; height: 600px"></div><script type="text/javascript">var timeline_json=', readr::read_lines("~/projects/timelineJS/trial.json") %>% paste(collapse=''),'; window.timeline=new TL.Timeline("timeline-embed", timeline_json);</script></body></html>', sep='')
write(html, file="~/projects/timelineJS/test.html")

产生的输出似乎是我想要的(为了可读性而进行了清理):

<!DOCTYPE html>
<html>
<head>
<link title="timeline-styles" rel="stylesheet" href="//cdn.knightlab.com/libs/timeline3/latest/css/timeline.css">
</head>
<body>
<script src="//cdn.knightlab.com/libs/timeline3/latest/js/timeline.js"></script>
<div id="timeline-embed" style="width: 100%; height: 600px"></div>
<script type="text/javascript">
var timeline_json = {"title": {"media": {"url": "//www.flickr.com/photos/tm_10001/2310475988/", "caption": "Whitney Houston performing on her My Love is Your Love Tour in Hamburg.", "credit": "flickr/<a href='http://www.flickr.com/photos/tm_10001/'>tm_10001</a>"}, "text": {"headline": "Whitney Houston<br/> 1963 - 2012", "text": "<p>Houston's voice caught the imagination of the world propelling her to superstardom at an early age becoming one of the most awarded performers of our time. This is a look into the amazing heights she achieved and her personal struggles with substance abuse and a tumultuous marriage.</p>"}}, "events": [{"media": {"url": "https://youtu.be/fSrO91XO1Ck", "caption": "", "credit": "<a href=\"http://unidiscmusic.com\">Unidisc Music</a>"}, "start_date": {"year": "1978"}, "text": {"headline": "First Recording", "text": "At the age of 15 Houston was featured on Michael Zager's song, Life's a Party."}}]};
window.timeline = new TL.Timeline("timeline-embed", timeline_json);
</script>
</body>
</html>

问题是,当我加载 html 文件时,什么也没有显示,当我检查控制台时,我收到错误 ReferenceError: TL is not Defined。但这对我来说没有意义,因为函数 TL.Timeline 是在 .js 文件的末尾显式定义的,该文件源自 html 正文。

我对 javascript 的了解还不足以尝试调试,所以我希望这里有人可能有一个想法。提前致谢!

最佳答案

@melpomene 在评论中提出了正确的问题,并让我查看 JS 文件是否正在加载。答案是不是因为<script>中提供的url标签无效。将“https:”添加到两个网址的开头即可使代码正常工作。

未定义 TL 的原因是由于 url 错误导致 JS 文件未加载。

关于Javascript引用错误: TL not defined even though it's explicity defined in *. js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32709272/

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