난수로 테이블을 채우고 사용자가 합계를 완성하도록 노력하고 있습니다. 합계를 입력 한 후 답을 확인하고 싶었고 답이 맞으면 답이 틀리면 더 이상 입력을 허용하지 않으려 고 셀을 강조 표시하고 사용자가 다시 시도 할 수 있도록했습니다.
표가 채워지고 오답이 식별되고 있지만 답변을 수정하려는 추가 시도는 피드백을 제공하지 않습니다. 입력 버튼을 여러 번 사용할 수없는 이유가 무엇인지 잘 모르겠습니다. 다른 항목을 수락하려면 무언가를 지워야한다고 생각합니다. 나는 JS로 놀고 있기 때문에 이것은 아마도 매우 간단하지만 작동하는 해결책을 찾을 수 없었습니다.
감사
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Testing</title>
<link href='https://fonts.googleapis.com/css? family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,800,700,600,300' rel='stylesheet' type='text/css'/>
<script type="text/javascript">
var ran = new Array(4);
var count = 0;
function randomArray ( )
{
count = 0;
var max = 10;
var min = 5;
for ( var i = 0; i < ran.length; ++i)
{
ran[i] = Math.floor(Math.random()*(max - min + 1) + min);
}
iter = Math.floor(Math.random()*(4));
iter2 = Math.floor(Math.random()*(4));
}
function fillRandom(id)
{
document.getElementById(id).innerHTML = ran[count];
count++;
}
function check(id, id2, i, j)
{
var ans = document.getElementById(id).value.toString();
var soln = document.getElementById(id2);
//document.getElementById(id2).style.border = "thick red double";
if (ans != (ran[i] + ran[j]))
{
soln.style.border = "thick red double";
correct = false;
}
else
{
soln.innerHTML = (ran[i] + ran[j]);
correct = true;
}
}
</script>
</head>
<body>
<h1>Testing</h1>
<input type="submit" value="Get Questions" onclick="randomArray();fillRandom('num1');fillRandom('num2');fillRandom('num3');fillRandom('num4');"/>
<p>Try the following questions:</p>
<table id="data" border="thin black">
<tr>
<td> </td>
<td id="A">A</td>
<td id="B">B</td>
<td>Total</td>
</tr>
<tr>
<td id="C">C</td>
<td id="num1"> </td>
<td id="num2"> </td>
<td id="t12"><input id="total_1_2" type="text" /></td>
</tr>
<tr>
<td id="D">D</td>
<td id="num3"> </td>
<td id="num4"> </td>
<td id="t34"><input id="total_3_4" type="text" /></td>
</tr>
<tr>
<td>Total</td>
<td id="t13" ><input type="text" id="total_1_3"/></td>
<td id="t24"><input type="text" id="total_2_4"/></td>
<td id="t"><input type="text" id="total"/></td>
</tr>
</table>
<br/>
<input type="submit" value="Check Total" onclick="check('total_1_2', 't12', '0', '1');check('total_3_4', 't34', '2', '3');check('total_1_3', 't13', '0', '2');
check('total_2_4', 't24', '1', '3')">
</body>
</html>
function check(id, id2, i, j)
{
var ans ;
if(document.getElementById(id) !== null)
ans = document.getElementById(id).value;
else
ans = document.getElementById(id2).textContent;
var soln = document.getElementById(id2);
if (ans != (ran[i] + ran[j]))
{
soln.style.border = "thick red double";
correct = false;
}
else
{
soln.innerHTML = (ran[i] + ran[j]);
soln.style.border = "none";
correct = true;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다