Sometimes it is necessary to add an online testing function to the web page, such as online surveys, online testing of various knowledge and other applications. Such applications require the use of many front-end and back-end skills. Today I will share with you a front-end application based on jQuery-testing the question answering function.
HTML
First load the jquery library file and quiz.js and the required CSS style file styles.css.
<script src="jquery.js"></script> <script src="quiz.js"></script> <link rel="stylesheet" href="styles.css" />
Then add div#quiz-container where the test questions need to be placed.
jQuery
First, we define the question and answer options. question is the question, answers are the answer options, and correctAnswer is the correct answer. It can be seen that the defined init is a json data format.
Next, we directly call the plug-in method provided by quiz.js, and then open the page to see that an online test project has been generated on the page.
$(function(){ $('#quiz-container').jquizzy({ questions: init.questions }); });
So, if you want to modify the custom test question style layout, you can make appropriate modifications in the quiz.js and styles.css files.
Questions
At this point, careful friends will find that the problem is coming:
1. Is it unsafe to directly mark the correct answer to the question in the js code? Whether the answer to a formal test project should be determined in the background to prevent someone from looking at the source code to directly obtain the correct answer.
2. How to interact with the background? For example, verify the identity before answering the test questions, and send the results to the backend after answering the questions.
What I want to say is that this is a front-end code demonstration project. The real application answers will not appear in the front-end code; quiz.js actually already has an interface for interacting with background ajax. We will do more in the following articles. Introduction, I have already thought of the title of the article: How to use jQuery PHP MySQL to implement an online testing project, so stay tuned.
View demo Download source code
The above is the entire content of this article, I hope you all like it.