Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Javascript中通过用户操作使反馈消失?_Javascript_Html - Fatal编程技术网

如何在Javascript中通过用户操作使反馈消失?

如何在Javascript中通过用户操作使反馈消失?,javascript,html,Javascript,Html,我需要向代码中添加什么,以便当用户单击按钮New或开始在输入字段中键入“userAnswer”进行第二次尝试时,反馈消失。 但是,当用户单击检查 这是代码的简化版本: 函数F1(){ Z1=document.getElementById(“Z1”); Z2=document.getElementById(“Z2”); rZ1=数学地板((数学随机()*10)); rZ2=数学地板((数学随机()*10)); Z1.innerHTML=rZ1; Z2.innerHTML=rZ2; 变量运算符1=

我需要向代码中添加什么,以便当用户单击按钮
New
或开始在输入字段
中键入“userAnswer”
进行第二次尝试时,反馈消失。 但是,当用户单击
检查

这是代码的简化版本:

函数F1(){
Z1=document.getElementById(“Z1”);
Z2=document.getElementById(“Z2”);
rZ1=数学地板((数学随机()*10));
rZ2=数学地板((数学随机()*10));
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
变量运算符1=['+','-'];
oper1=document.getElementById(“operator1”);
op1=运算符1[数学楼层(数学随机()*2)];
oper1.innerHTML=op1;
rnd=parseFloat(eval(rZ1+op1+rZ2));
answer.innerHTML=rnd;
}
函数F2(){
antw=parseFloat(document.getElementById(“userAnswer”).value);
反馈=document.getElementById(“反馈”);
ant=document.getElementById(“答案”).textContent;
{
if(antw==ant){
feedBack.textContent=“好”;
}否则{
feedBack.textContent=“坏”;
}
}
};
新建
= 
检查


添加到F1函数

document.getElementById('feedBack').classList.add('hidden');
如果存在元素,则向CSS添加隐藏类的新条目以隐藏元素。

如果按下check(检查)按钮,则显示反馈,请删除该类中的类似内容

document.getElementById('feedBack').classList.remove('hidden');
函数F1(){
Z1=document.getElementById(“Z1”);
Z2=document.getElementById(“Z2”);
rZ1=数学地板((数学随机()*10));
rZ2=数学地板((数学随机()*10));
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
变量运算符1=['+','-'];
oper1=document.getElementById(“operator1”);
op1=运算符1[数学楼层(数学随机()*2)];
oper1.innerHTML=op1;
rnd=parseFloat(eval(rZ1+op1+rZ2));
answer.innerHTML=rnd;
document.getElementById('feedBack').classList.add('hidden');
}
函数F2(){
antw=parseFloat(document.getElementById(“userAnswer”).value);
反馈=document.getElementById(“反馈”);
ant=document.getElementById(“答案”).textContent;
{
if(antw==ant){
feedBack.textContent=“好”;
}否则{
feedBack.textContent=“坏”;
}
}
document.getElementById('feedBack').classList.remove('hidden');
};
.hidden{可见性:hidden;}
新建
= 
检查


添加到F1函数

document.getElementById('feedBack').classList.add('hidden');
如果存在元素,则向CSS添加隐藏类的新条目以隐藏元素。

如果按下check(检查)按钮,则显示反馈,请删除该类中的类似内容

document.getElementById('feedBack').classList.remove('hidden');
函数F1(){
Z1=document.getElementById(“Z1”);
Z2=document.getElementById(“Z2”);
rZ1=数学地板((数学随机()*10));
rZ2=数学地板((数学随机()*10));
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
变量运算符1=['+','-'];
oper1=document.getElementById(“operator1”);
op1=运算符1[数学楼层(数学随机()*2)];
oper1.innerHTML=op1;
rnd=parseFloat(eval(rZ1+op1+rZ2));
answer.innerHTML=rnd;
document.getElementById('feedBack').classList.add('hidden');
}
函数F2(){
antw=parseFloat(document.getElementById(“userAnswer”).value);
反馈=document.getElementById(“反馈”);
ant=document.getElementById(“答案”).textContent;
{
if(antw==ant){
feedBack.textContent=“好”;
}否则{
feedBack.textContent=“坏”;
}
}
document.getElementById('feedBack').classList.remove('hidden');
};
.hidden{可见性:hidden;}
新建
= 
检查


我在代码末尾添加了一个函数,以便在
反馈中消失,并在
F1
F2
中添加了一行,以便在
反馈中显示和消失(我在这些行上添加了注释)

函数F1(){
Z1=document.getElementById(“Z1”);
Z2=document.getElementById(“Z2”);
rZ1=数学地板((数学随机()*10));
rZ2=数学地板((数学随机()*10));
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
变量运算符1=['+','-'];
oper1=document.getElementById(“operator1”);
op1=运算符1[数学楼层(数学随机()*2)];
oper1.innerHTML=op1;
rnd=parseFloat(eval(rZ1+op1+rZ2));
answer.innerHTML=rnd;
document.querySelector('p#feedBack').style.display='none'//添加此
document.querySelector('#userAnswer')。值=''
}
函数F2(){
antw=parseFloat(document.getElementById(“userAnswer”).value);
反馈=document.getElementById(“反馈”);
ant=document.getElementById(“答案”).textContent;
{
if(antw==ant){
feedBack.textContent=“好”;
}否则{
feedBack.textContent=“坏”;
}
}
document.querySelector('p#feedBack').style.display='block'//添加此
};
document.querySelector(“#userAnswer”).addEventListener('keydown',event=>{
if(document.querySelector('p#feedBack').style.display=='block')
document.querySelector('p#feedBack').style.display='none'
})
新建
= 
检查


我在代码末尾添加了一个函数,以便在
反馈中消失,并在
F1
F2
中添加了一行,以便在
反馈中显示和消失(我在这些行上添加了注释)

函数F1(){
Z1=document.getElementById(“Z1”);
Z2=document.getElementById(“Z2”);
rZ1=数学地板((数学随机()*10));
rZ2=数学地板((数学随机()*10));
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
变量运算符1=['+','-'];
oper1=document.getElementById(“operator1”);
op1=运算符1[数学楼层(数学随机()*2)];
oper1.innerHTML=op1;
rnd=parseFloat(eval(rZ1+op1+rZ2));
answer.innerHTML=rnd;
document.querySelector('p#feedBack').style.display='none'//添加此
document.querySelector('#userA