如何在HTML和JavaScript中创建投票按钮? [英] How to create a voting button in HTML and javascript only?

查看:164
本文介绍了如何在HTML和JavaScript中创建投票按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个网站,允许用户投票选择页面上显示的两张图片之一。

我的要求是:

1)只有1用户应该可以投票一次

2)投票后,结果应该出现在页面上(投票图像上方)



真的感谢帮助!



我尝试过:



创建正常带计数器的投票按钮

I am making a website which will allow a user to vote for one of the two images present on the page.
My requirements are:
1) Only 1 user should be able to vote once
2) After voting, results should appear on the page (above the image voted)

Would really appreciate help!

What I have tried:

Created a normal voting button with counter

推荐答案

除非您从未关闭页面并将投票记录存储在页面上,否则您实际上无法做您想做的事情。



JavaScript是一种客户端语言。您需要存储数据(在服务器上)并且需要服务器端语言(我更喜欢php)。然后,您可以在SQL类型数据库中(甚至在服务器端平面文件中)将投票记录存储在服务器上。



每人一票:您需要确定一种唯一识别每个用户的方法,然后注意(再次,服务器端)他们是否投票。您可以保留投票和投票的单独标签,或者,如果隐私无关紧要,请将它们保持在一起(允许更改)。



所以 - 这里是一个开始的地方: PHP教程 [ ^ ]



既然平面文件是可能的,虽然效率低下,你没有SQL就可以逃脱



您的服务器需要支持PHP,数据库等吗? Vertigo [ ^ ]非常好且免费。





Unless you never close the page and store the voting tally on the page, you really cannot do what you want to do.

JavaScript is a client-side language. You need to store the data (on the server) and that requires a server side language (I prefer php). You can then store the vote tally on the server in SQL type database (or even in a server-side flat file).

The one vote per person: you need to determine some method of uniquely identifying each user, and then noting (again, server side) if they've voted or not. You can keep separate tallies of who voted and the votes, or, if privacy is of no concern, keep them together (allowing changes, possibly).

So - here's a place to start: PHP Tutorial[^]

Since flat files are a possibility, although inefficient, you can get away without SQL.

Need support on your server for PHP, a database, etc., ? Vertigo[^] is very good and free.




这篇关于如何在HTML和JavaScript中创建投票按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆