[英]How can I add a string to an array when a checkbox is checked?
These are my strings and their speeds at which they will be displayed这些是我的字符串及其显示速度
var typed = new Typed(".auto-input", {
strings: ["Hi, blahblahblah.", "blahblahblah...", "...blahblahblah?"],
typeSpeed: 75,
backSpeed: 75,
loop: true
});
This is my code for when my checkbox is checked这是我的复选框被选中时的代码
var checkbox = document.getElementById('checkbox');
checkbox.addEventListener('change', () => {
document.body.classList.toggle('dark');
});
I tried an if statement我试过 if 语句
if (document.body.classList.toggle('dark')) {
typed.push(["lorem"]);
}
But then i realized, i think i need to select the "strings" in my "typed" vaiable.但后来我意识到,我想我需要 select 我的“类型”变量中的“字符串”。 I'm not quite sure how to do that.我不太确定该怎么做。 I apologize in advance for any mistakes, this is my first question posted on StackOverflow.对于任何错误,我提前道歉,这是我在 StackOverflow 上发布的第一个问题。
As you want to push "lorem"
into strings
inside Typed
, your if statement should look like:当您想将"lorem"
推入Typed
内的strings
时,您的 if 语句应如下所示:
if (document.body.classList.toggle('dark')) {
typed.strings.push("lorem");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.