javascript - 实现如下图的投票功能
实现功能如下:1.点击投票记录数据,下面的进度条也随之改变!
回复内容:
实现功能如下:1.点击投票记录数据,下面的进度条也随之改变!
这个点击有的时候,上边加1,点击否,否上边加1。进度条,分两部分吧,一开始两边都是50%,然后分别获取有和否的上面的个数,除以有和否之和,然后把小数点拼接转换成百分比,分别赋值给有和否所占的比例,最后再把算出比例所占的宽,赋值给有和否所占的宽。更新进度条。
首先需要用Ajax像后台php提交投票 成功失败返回提示
jq下:
在Ajax中 success 中对进度条进行操作 如果是用宽度控制 直接修改两侧的百分比然后调整宽度
没测试 大意是这样
<code>$.ajax({ url:"url", dataType:"json", type:'POST', data:{ 'vote': 'red', 'user': 1 }, success: function(data) { if(data['err'] == 1){ alert('repeat err'); }else{ $('#ProgressRed').css({"width":data['score']}); $('#ProgressBlue').css({"width":100 - data['score']}); } }, error: function(x) { if (console) { console.log(x); } } }); </code>
这个的思路是这样:
下面的进度条分为三个div:container div、blue div 、red div
也就是说点击投票时需要分别计算蓝红div的进度,加起来综合是100%。
用ajax吧,提交数据返回处理好的比例进行显示就ok了
具体实现你需要整理一下:
我先提供一个链接,
http://seiyria.com/bootstrap-slider/
可以参考一下:http://www.cnblogs.com/zxyun/
可以解决下面拖动条(禁用拖动事件)的显示问题,
然后上面和下面分两步处理,上面做数据操作,下面做数据显示,不同步操作!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
