如何将输入脚本放在 html 文件之外?
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
});
});
我有我的网站,有一个脚本可以在 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
});
});