[英]How do i put my typing script outside my html file?
我有我的網站,有一個腳本,在span
中的h2
之后鍵入一系列內容。
首先,我必須將腳本包含在 html 文件中,整個 js 腳本,在 html 文件中也太長而且太無用了。 所以我試圖把它放在我的 html 文件之外,並像這樣包含它。
<script src="javascript/index.js"></script>
但是我的span
沒有任何反應
<h2>I am <span id="typing"></span></h2>
這是我的 index.js
var typed = new Typed('#typing', {
strings: ['first thing', 'second thing'],
typeSpeed: 30,
loop: true
});
你需要等待dom被加載。
document.addEventListener("DOMContentLoaded", function(event) {
var typed = new Typed('#typing', {
strings: ['first thing', 'second thing'],
typeSpeed: 30,
loop: true
});
});
你定義 index.js 的方式,你必須把它放在一個名為 javascript 的文件夾中,如果你不想要那個文件夾,只需說<script src = "index.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.