请给我一个普通的 JS 解决方案,因为我是编码新手,引入库只会让我更加困惑。
我在程序中有两个函数:changeText 包含异步 setTimeout 函数,它在 X 秒内淡入淡出文本,而 userNameinput 允许用户输入文本输入,然后在浏览器上显示输入。
我遇到的问题是 usernameinput 与 changeText 函数一起执行。我的目标是让 changeText 函数首先执行并完成,然后让 userNameInput (出现文本输入行)在之后立即执行。
正如您在我的代码中看到的,我已经实现了一个回调以尝试解决这个问题。我创建了一个名为welcome 的新函数,将changeText 和useNameInput 函数捆绑在一起,这样当调用welcome 时,它会先执行changeText,完成,然后调用封装在回调中的userNameInput。不知何故,我相信由于 changeText 函数中的 setTimeout 函数在 Javascript 环境之外的队列中放置了 X 时间,JS 看到堆栈中没有任何内容并继续执行 usernameInput 而无需等待。请帮忙!卡了太久了!提前致谢。
HTML:
<div id="h1">Hello,<br></div>
<div id="inputDiv"></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#h1{
opacity: 0;
transition: 1s;
}
Run Code Online (Sandbox Code Playgroud)
JS:
function fadeIn() {
document.getElementById('h1').style.opacity = '1';
}
function fadeOut() {
document.getElementById('h1').style.opacity = '0';
}
var dialogue = ['Hello,', 'My name is Jane.', 'I have a dog!', 'What is your name?'];
var …Run Code Online (Sandbox Code Playgroud) 我收到错误“分段错误”。我认为它与 isdigit(argv[i]) 行有关,但不明白为什么。
#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
//implement commandline arguments
int main(int argc, string argv[])
{
//convert string element in array to integer
int key = atoi(argv[1]);
//check that user input for key is no more than 2 memory spots, not a negative number and a single input
if (argc != 2 || key < 0 || isdigit(argv[1]))
{
printf("useage: ./caesar key\n");
return 1;
}
else
{
string plaintext = get_string("plaintext: "); …Run Code Online (Sandbox Code Playgroud)