Home Web Front-end JS Tutorial Voting system display results plug-in based on jQuery_jquery

Voting system display results plug-in based on jQuery_jquery

May 16, 2016 pm 06:03 PM
voting system

First, let’s take a look at the running effect, as shown in Figure 1.

Steps to use this plug-in
1. Import the css file
First, import the css style file 'votecss.css' into the page, which is necessary for the normal display of voting results. Less. The specific code is as follows:
<link href="startpic/votecss.css" rel="stylesheet" type="text/css" />
2. The source file that introduces jQuery is the source file
The plug-in is based on jQuery, so the specific code required to introduce the jQuery plug-in is as follows:
<script type="text/javascript" src="startpic/jquery.js"></script>
3. Introducing the voting plug-in
Introducing the self-developed voting plug-in "Studyplay_vote.js", the specific code is as follows:
<script src="startpic/Studyplay_vote.js"></script>
4. Page call
First add a div element with ID 'z' to the page and write JavaScript code to display the voting results. The specific code is as follows:
Copy Code The code is as follows:

<script type="text/javascript">
$(document).ready(function(){
$("#z").study_vote([{"options":"Good review","data":"16","color":"#39c"},{"name":"Medium review"," data":"10","color":"#f00"},{"name":"Bad review","data":"30","color":"#000"}]);
});
</script>

The effect of running this code is shown in Figure 1.
Note: This plug-in has two parameters
1. Options is a required plug-in. It is an object data. The specific form is as follows.
[{},{}...{}]The number of this array is the number of voting options. If there are ten voting options, this array must be 10; {} is json data, there are three items in total .
"name" represents the name of the voting option;
"data" represents the number of votes for this option;
"color" represents the column color of this option.
2. The totle optional parameter can be omitted. Indicates the total number of votes cast, mainly used for calculating percentages for multiple choice votes.

The specific code of the plug-in
Copy the code The code is as follows:

$. fn.study_vote= function(options,totle){
var settings=options;
if(totle!=null)
{
if(isNaN(totle))
{
alert('Parameter error');
return;
}
}
if(typeof(settings)!='object')
{
alert('Parameter error') ;
return;
}
var container = jQuery(this);
container.html('<dl id="studyvote"></dl>');
var study_voteCount=0;
if(totle==null||totle=='')
{//Single vote
for(i=0;i<settings.length;i )
{
study_voteCount = parseInt(settings[i].data);
}
}
else
{//Multiple votes
study_voteCount = parseInt(totle);
}
var study_votestr="";
for(i=0;i<settings.length;i )
{
var studyplay_present=settings[i].data/study_voteCount*100;
if(parseInt(studyplay_present)!=studyplay_present)
{
studyplay_present=studyplay_present.toFixed(2);
}
study_votestr ='<dd class="dd"><div class="fl">' settings[i].name ':</div><div class="outbar"><div class="inbar" style="width:' studyplay_present '%;background :' settings[i].color ';"></div></div> <div class="fl">' studyplay_present '% </div></dd>';
}
container.find('#studyvote').html(study_votestr)
}

Plug-in download
Demo addresshttp://demo.jb51 .net/js/2011/studyplayvote/index.html
The download address of this file is:
studyplayvote.rar
I hope friends can download and use it. If you have any questions, thank you for your feedback.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Develop web voting system using JavaScript Develop web voting system using JavaScript Aug 09, 2023 pm 01:30 PM

Develop web voting system using JavaScript

Multi-user online voting system implemented in PHP Multi-user online voting system implemented in PHP Aug 10, 2023 pm 05:49 PM

Multi-user online voting system implemented in PHP

How to implement a simple voting system using MySQL and Ruby How to implement a simple voting system using MySQL and Ruby Sep 20, 2023 pm 12:37 PM

How to implement a simple voting system using MySQL and Ruby

How to develop an online voting system using Laravel How to develop an online voting system using Laravel Nov 02, 2023 pm 06:31 PM

How to develop an online voting system using Laravel

How to write a simple voting system in C++? How to write a simple voting system in C++? Nov 04, 2023 am 11:24 AM

How to write a simple voting system in C++?

User interface design and optimization of PHP online voting system User interface design and optimization of PHP online voting system Aug 09, 2023 pm 08:45 PM

User interface design and optimization of PHP online voting system

How to use PHP to develop a voting system for WeChat public accounts How to use PHP to develop a voting system for WeChat public accounts Oct 27, 2023 pm 12:12 PM

How to use PHP to develop a voting system for WeChat public accounts

Blockchain voting system in PHP Blockchain voting system in PHP Jun 11, 2023 pm 12:03 PM

Blockchain voting system in PHP

See all articles