


Example showing JS implementing a simple multiple-choice assessment system
This article will share with you the example code of a simple multiple-choice assessment system implemented in js. It is very good and has reference value. Friends who need it can refer to it
Includes content: JS encapsulation form, JS verification form
It is said to be an evaluation system, but it feels like it can only be regarded as a small demo. It is very watery, has no database, and only uses JS to make a simple multiple-choice evaluation system.
----- -------------------------------------------------- --------------------------
1. Design ideas
Form encapsulation:
[1] Since it is submitted using JS encapsulation, there is no need for form tags
[2] Place multiple input tags as input items
【3】Write JS to obtain input items and submit them to another page through get method
Verification form (display results)
【1】Get the parameters passed in by get
【2】Parse through JS
【3】Display to the corresponding location
----------------------- -------------------------------------------------- -------
##2. The reference source code is as follows
request.html<html> <head> <title>考试系统</title> <meta http-equiv="accept-charset" charset="utf-8"> <script src="jquery.min.js"></script> <script type="text/javascript"> function getjson() { var radio = new Array(); for (var i = 1; i <= 5; i++) {//获取radio的值 var radio_name = new String("radio_" + i); radio[i - 1] = $('input:radio[name=' + radio_name + ']:checked').val() } for (var i = 1; i <= 2; i++) {//获取checkbox的的输入 var checkbox_name = new String("checkbox_" + i); var chk_value = []; $('input:checkbox[name=' + checkbox_name + ']:checked').each(function () { chk_value.push($(this).val()); }); radio[i + 4] = "";//置为空 for (var j = 0; j < chk_value.length; j++) { radio[i + 4] = radio[i + 4] + chk_value[j]; } } //数组转json串 var json = JSON.stringify(radio); return json; } function my_confirm() { var json = getjson(); var msg = "您真的答案是:" + json + ",是否确认提交"; if (confirm(msg) == true) { window.location.href = "result.html?radio=" + 5 + "checkbox=" + 2 + "&json=" + json; } else { return false; } } $(function () { var m = 1; var s = 10; setInterval(function () { if (m >= 0) { if (s < 10) { $('#time').html("剩余时间:" + m + ':0' + s); } else { $('#time').html("剩余时间:" + m + ':' + s); } s--; if (s < 0) { s = 59; m--; } if (m == 0 && s < 1) { window.location.href = "result.html?radio=" + 5 + "checkbox=" + 2 + "&json=" + getjson(); } } }, 1000) }) </script> </head> <body> <h3 id="学年期末测试题">2016--2017学年期末测试题</h3> <p id="time" style="color:red;float: right;margin: 12px 20px 0 0;padding: 0 0 0 0;font-size: xx-large"></p> <br/><br/><br/> <hr/> <h4 id="一-单选题-每题-分-满分-分">一、单选题(每题12分,满分60分)</h4> 1.当方法遇到异常又不知如何处理时,下列() 做法是正确的。<br> <input type="radio" name="radio_1" value="A">A、捕获异常<br> <input type="radio" name="radio_1" value="B">B、抛出异常<br> <input type="radio" name="radio_1" value="C">C、声明异常<br> <input type="radio" name="radio_1" value="D">D、嵌套异常<br> 2.下列说法错误的是() <br> <input type="radio" name="radio_2" value="A">A、在java中一个类被声明为final类型,表示该类不能被继承。<br> <input type="radio" name="radio_2" value="B">B、当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,这叫引用传递。<br> <input type="radio" name="radio_2" value="C">C、一个类不能既被声明为 abstract,又被声明为final。<br> <input type="radio" name="radio_2" value="D">D、方法的覆盖(Overriding)和重载(Overloading)是Java多态性的表现,他们没有区别。<br> 3.下列创建数组的方法哪个是错误的? <br> <input type="radio" name="radio_3" value="A">A、Date[] arr = new Date[5];<br> <input type="radio" name="radio_3" value="B">B、Date arr[] = new Date[];<br> <input type="radio" name="radio_3" value="C">C、Date arr[][] = new Date[4][5];<br> <input type="radio" name="radio_3" value="D">D、Date arr[][] = new Date[4][];<br> 4.在读文件Employee.txt 时,可以直接使用该文件作为参数的类是() <br> <input type="radio" name="radio_4" value="A">A、BufferedReader<br> <input type="radio" name="radio_4" value="B">B、FileInputStream<br> <input type="radio" name="radio_4" value="C">C、DataOutputStream<br> <input type="radio" name="radio_4" value="D">D、DataInputStream<br> 5.下列关于线程的说法中,错误的是? <br> <input type="radio" name="radio_5" value="A">A、线程必须通过方法start() 来启动。<br> <input type="radio" name="radio_5" value="B">B、线程创建后,其优先级是可以改变的。<br> <input type="radio" name="radio_5" value="C">C、实现Runnable接口或者从Thread类派生的线程类没有区别。<br> <input type="radio" name="radio_5" value="D">D、当对象用synchronized 修饰时,表明该对象在任一时刻只能由一个线程访问。<br> <br/> <h4 id="二-多选题-每题-分-满分-分-错选-少选-多选不得分">二、多选题(每题20分,满分40分,错选、少选、多选不得分)</h4> 6.下列说法正确的是() <br> <input type="checkbox" name="checkbox_1" value="A">A、在java中一个类被声明为final类型,表示该类不能被继承。<br> <input type="checkbox" name="checkbox_1" value="B">B、当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,这叫引用传递。<br> <input type="checkbox" name="checkbox_1" value="C">C、一个类不能既被声明为 abstract,又被声明为final。<br> <input type="checkbox" name="checkbox_1" value="D">D、方法的覆盖(Overriding)和重载(Overloading)是Java多态性的表现,他们没有区别。<br> 7.当方法遇到异常又不知如何处理时,下列() 做法是不正确的。<br> <input type="checkbox" name="checkbox_2" value="A">A、捕获异常<br> <input type="checkbox" name="checkbox_2" value="B">B、抛出异常<br> <input type="checkbox" name="checkbox_2" value="C">C、声明异常<br> <input type="checkbox" name="checkbox_2" value="D">D、嵌套异常<br> <hr/> <input type="button" onclick="my_confirm()" value="考试完成"> </body> </html>---- -------------------------------------------------- --------------------------result.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>考试结果</title> <script src="jquery.min.js"></script> <script> //获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } function showResult() { var answer = ["B", "D", "B", "B", "D", "ABC", "ACD"];//标准答案 var answer_score = [12, 12, 12, 12, 12, 20, 20];//答案的分数 var user_answer = JSON.parse(getUrlParam("json"));//获取用户答案 var radio_num = parseInt(getUrlParam("radio"));//获取单选个数 var checkbox_num = parseInt(getUrlParam("checkbox"));//获取多选个数 var radio_result = 0;//单选分数 var checkbox_result = 0;//多选分数 var radio_right_num = 0;//单选答对个数 var checkbox_right_num = 0;//多选答对个数 var result = 0;//总分数 var user_answer_result = new Array();//用户没到题的答题情况 for (var i = 0; i < user_answer.length; i++) { if (user_answer[i] == answer[i]) { if (i < radio_num) { radio_result = radio_result + answer_score[i]; radio_right_num++; } else { checkbox_result = checkbox_result + answer_score[i]; checkbox_right_num++; } user_answer_result[i] = "正确"; } else { user_answer_result[i] = "错误"; } } result = checkbox_result + radio_result; //结果展示 var show_result1; var show_result2; var show_result3; var show_result4; var show_result5; var show_result6; show_result1 = "你的答案结果为:"; for (var i = 0; i < user_answer.length; i++) { show_result1 = show_result1 + (i + 1) + ":" + user_answer_result[i] + "; "; } show_result2 = "总题目个数:" + user_answer.length; show_result3 = "答对单选题题目个数:" + radio_right_num + "; 得分:" + radio_result; show_result4 = "答对多选题题目个数:" + checkbox_right_num + "; 得分:" + checkbox_result; show_result5 = "答错题目个数:" + (user_answer.length - radio_right_num - checkbox_right_num); show_result6 = " 本次考试总成绩为:" + result; $("p#show_result1").html(show_result1); $("p#show_result2").html(show_result2); $("p#show_result3").html(show_result3); $("p#show_result4").html(show_result4); $("p#show_result5").html(show_result5); $("p#show_result6").html(show_result6); } </script> </head> <body> <h2 id="考试结束">考试结束!</h2> <hr/> <input type="button" onclick="showResult()" value="查看结果"> <p id="show_result1"> <p> <hr/> <p id="show_result2"></p> <p id="show_result3"></p> <p id="show_result4"></p> <p id="show_result5"></p> <hr/> <p id="show_result6"></p> </body> </html>The result is as shown below:
The above is the detailed content of Example showing JS implementing a simple multiple-choice assessment system. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function