gpt4 book ai didi

javascript - 发送关键方法

转载 作者:行者123 更新时间:2023-12-03 10:54:01 25 4
gpt4 key购买 nike

嗨,我听到了关于我遇到的问题的不同解决方案,我将解释我想要做什么以及我正在做什么。我正在做一个“ react 测试”,基本上你要做的就是当你看到一个数字弹出 B 或 R 时按下两个按钮。所以但问题是我需要以某种方式发送哪个键在测试期间被按下到“结果文件”而不向用户显示。我听说你可以用 cookies 来做到这一点,你可以使用隐藏的输入类型并将其发送到下一页,你可以使用 document.write、createelement 或只使用 GET 和 POST 方法。所以我的问题是我应该怎么做,用哪种方式,如果我能得到一些关于代码的帮助,我不会哭。我了解 HTML、CSS、jQuery 和 JavaScript,我不需要任何 PHP 解决方案。这里有三页,所以你可以知道它是什么样子,前两页几乎是不同的颜色和形状,所以我只使用其中一页。

输入隐藏的test.html ||输入隐藏测试1.html:

<!DOCTYPE html>
<html>
<head>
<title>Input hidden test</title>
<style>
#first-child {
width: 200px;
height: 200px;
background: white;
border-radius: 0%;
margin-top: 150px;
margin-bottom: 50px;
margin-left: 550px;
margin-right: 0px;
-webkit-animation: myfirst 1s;
-moz-animation: myfirst 1s;
animation: myfirst 1s;
}
@-webkit-keyframes myfirst {
0% {background: white;}
20% {background: white;}
40% {background: white;}
60% {background: white;}
80% {background: white;}
100% {background: red;}
}
@keyframes myfirst {
0% {background: white;}
20% {background: white;}
40% {background: white;}
60% {background: white;}
80% {background: white;}
100% {background: red;}
}
#first-parent {
color: blue;
margin-top: 5px;
margin-bottom: 50px;
margin-left: 600px;
margin-right: 0px;
}
#second-parent {
color: red;
margin-top: 0px;
margin-bottom: 50px;
margin-left: 40px;
margin-right: 0px;
}
p {
margin-left: 640px;
}
</style>
</head>
<body>

<div id="first-child"></div>

<button id="first-parent" onclick="">B</button>
<button id="second-parent" onclick="">R</button>
<br />
<p>1/2</p>
<script>
document.onkeypress = function(e) {
e = e || window.event;
var charCode = e.charCode || e.keyCode,
character = String.fromCharCode(charCode);

console.log(charCode);
window.location.href="Input hidden test 1.html";
};
</script>
</html>

输入隐藏测试2.html:

<!DOCTYPE html>
<html>
<head>
<title>Input hidden test 2</title>
<style>

</style>
</head>
<body>

<script>

</script>
</html>

差不多就这些了,有什么问题就问吧,祝好!

最佳答案

问题的最终答案

Test1.html

<!DOCTYPE html>
<html>
<head>
<title>Input hidden test</title>
</head>
<body>

<div>
<h1>1. Who is the president of America?</h1><br/>
A) Bush <br />
B) Obama <br />
C) Clinton <br />
D) yourself .
</div>

<p>1/2</p>



<script>
document.onkeypress = function(e) {
e = e || window.event;
var charCode = e.charCode || e.keyCode,
character = String.fromCharCode(charCode);
var answer;
if((e.keyCode>64 && e.keyCode<69)||(e.keyCode>96 && e.keyCode<101) ){
if(e.keyCode==65 || e.keyCode==97){
answer='A';
} else if(e.keyCode==66|| e.keyCode==98){
answer='B';
}else if(e.keyCode==67|| e.keyCode==99){
answer='C';
}else if(e.keyCode==68|| e.keyCode==100){
answer='D';
}
localStorage.setItem("keypressed","");
localStorage.setItem("keypressed","<h1>1. Who is the president of America?</h1><br /> your Answer :" +answer +"<br />Correct Answer : B<br />");
window.location.href="test1.html";
return true;
}
else{
alert("press A or B or C or D");
return false;
}

};
</script>
</html>

Test2.html

<!DOCTYPE html>
<html>
<head>
<title>Input hidden test</title>

</head>
<body>

<div id="first-child"></div>

<button id="first-parent" onclick="">B</button>
<button id="second-parent" onclick="">R</button>
<br />

<div>
2. Who is the princess of Sweden?
A) mary <br />
B) jones <br />
C) You <br />
D) Someone .
</div>

<p>2/2</p>



<script>
document.onkeypress = function(e) {
e = e || window.event;
var charCode = e.charCode || e.keyCode,
character = String.fromCharCode(charCode);
var answer;
if((e.keyCode>64 && e.keyCode<69)||(e.keyCode>96 && e.keyCode<101) ){
if(e.keyCode==65 || e.keyCode==97){
answer='A';
} else if(e.keyCode==66|| e.keyCode==98){
answer='B';
}else if(e.keyCode==67|| e.keyCode==99){
answer='C';
}else if(e.keyCode==68|| e.keyCode==100){
answer='D';
}
var res= localStorage.getItem("keypressed");
res+="<h1>2. Who is the princess of Sweden?</h1><br /> your Answer :" +answer +"<br />Correct Answer : C <br />";
localStorage.setItem("keypressed",res);
window.location.href="result.html";
return true;
}
else{
alert("press A or B or C or D");
return false;
}

};
</script>
</html>

RESULT.HTML

<!DOCTYPE html>
<html>
<head>
<title>Input hidden test 2</title>
<style>

</style>
</head>
<body>
<div id="result"></div>
<script>
var result= localStorage.getItem("keypressed");
document.getElementById('result').innerHTML= result;
//alert(result);
</script></html>

关于javascript - 发送关键方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28332245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com