JavaScript code for an online answer

Source: Internet
Author: User
Tags array continue eval split tostring
javascript| Online

<title> Online Answer--the snow in the northern </title>
<script language=javascript>
<!--
var tlist=t1_1,t1_2,t2_1
var tk=new Array ()//Item Bank
First question
Tk[t1_1]=new Array ();
Tk[t1_1][code]=1
Tk[t1_1][result]= Beijing
Tk[t1_1][score]=5

Tk[t1_2]=new Array ();
tk[t1_2][code]=2
Tk[t1_2][result]= Tokyo
Tk[t1_2][score]=8

Second question
Tk[t2_1]=new Array ();
Tk[t2_1][code]=3
Tk[t2_1][result]= Week Pen Chang
Tk[t2_1][score]=7

var points=0;
The volume of a contract
function Fncsubmit () {
points=0;
var arrt=tlist.split (', ');
for (Var i=0;i<arrt.length;i++)
{
var tinput=eval (Document.form1. + arrt[i]);
if (!tinput) continue;
var Tinputvalue=tinput.value;
if (Tinputvalue==tk[arrt[i]][result])
Points+=tk[arrt[i]][score]
}
document.getElementById (Oscore). innertext= Score: + points.tostring ();
}

Show correct answers
function Showresult () {
var arrt=tlist.split (', ');
var resultlist=new String ();
resultlist=;
for (Var i=0;i<arrt.length;i++)
{
var tinput=eval (Document.form1. + arrt[i]);
if (!tinput) continue;
var Tinputvalue=tinput.value;
Resultlist = resultlist + tk[arrt[i]][code].tostring () +: + Tk[arrt[i]][result] + (+ tk[arrt[i]][score] + min) +;
}
document.getElementById (oresult). innerhtml= Standard Answer: + resultlist.tostring ();
}
-->
</SCRIPT>
<style>
. line_r {font-size:12px; color: #000000; background:; border:none; border-bottom:solid 1px #000000; text-align:left;}
</style>

<body>
<form Name=form1 id=form1>
Online Answer:
<br><br>
1, the capital of China is <input class=line_r type=text name=t1_1 Value=>, the capital of Japan is <input class=line_r type=text. name=t1_2 ><br>
2, 2005 Mon Yogurt Super Girls runner-up is <input class=line_r type=text name=t2_1 value= ><br><br>
<input Type=button NAME=BTN1 Value= submitted Onclick=fncsubmit () >
<input Type=button name=btn2 value= correct answer onclick=showresult ();>
<br>
<span id=oscore></span>
<br>
<span id=oresult></span>
</form>
</body>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.