简体   繁体   English

每当有人单击按钮时,如何为变量分配1?

[英]How can I 1 to a variable for every time someone clicks a button?

I have this algorithm to calculate the average of votes which is: (a + 2b + 3c + 4d + 5e + 6f + 7g + 8h + 9i + 10j) / (a + b + c + d + e + f + g + h + i + j) 我有这种算法来计算平均票数:(a + 2b + 3c + 4d + 5e + 6f + 7g + 8h + 9i + 10j)/(a + b + c + d + e + f + g + h + i + j)

But the problem is that I want to add one to a variable for every click someone clicks and display the average after reload. 但是问题是我想为某人点击的每次点击添加一个变量,并在重新加载后显示平均值。

ex:. a = 25 //the amount of people who voted "1";
     b = 19 //the amount of people who voted "2";
     c = 78 //the amount of people who voted "3";
     d = 98 //the amount of people who voted "4";
     e = 69 //the amount of people who voted "5";
     average = (a + 2b + 3c + 4d + 5e + 6f + 7g + 8h + 9i + 10j) / (a + b + c + d + e + f + g + h + i + j);
     alert(average); // Alerts 3,5

Someone clicks "d", and ten other people click "e" 有人单击“ d”,其他十个人单击“ e”

 adds +1 to "d"

 adds +1 to "e" (10x)

 alerts the new average on reload.

Thats what I want it to do but I don't know how to work with cookies (if its necessary) 那就是我想要它做的事,但是我不知道如何使用Cookie(如果需要)

If you are just creating this single web page to allow people to vote then you can simply do it all in memory by not refreshing the page like as if every single voter is coming to this computer and placing their vote. 如果您只是创建允许人们投票的单个网页,则只需在内存中完成所有操作即可,而无需刷新页面,就像每个投票者都来这台计算机并进行投票一样。 That is like asking all your voters to come to your computer and place the vote. 这就像要求所有选民使用计算机进行表决。

It is a strange question because typically if you are allowing people to use your web page from different client browser ( their computers ) then you need some other server side mechanism to keep track of the votes. 这是一个奇怪的问题,因为通常如果您允许人们从其他客户端浏览器(他们的计算机)使用您的网页,那么您需要其他服务器端机制来跟踪投票。 Cookies will be different for each client and will not work. 每个客户的Cookie都将有所不同,并且将无法正常工作。 May be use PHP as server side language for keeping track of votes on the server. 可以使用PHP作为服务器端语言来跟踪服务器上的投票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人单击类似Facebook的按钮后,如何关闭引导程序模式? - How can I close a bootstrap modal after someone clicks a facebook like button? 当有人单击按钮时,如何打开JavaScript文件? - How do i open a javascript file, when someone clicks on a button? 每当用户单击同一按钮时,如何显示N个div? - How do I show N divs every time user clicks same button? 每次打开模式时如何计算按钮的点击次数 - how calculate number of clicks on a button every time modal is open 我如何创建一个表格,每次用户点击它时都会附加一列 - How can I create a table that appends a column every time a user clicks on it 如何制作同时点击 div 的每个子元素的 function? - How can I make a function that clicks in every child element of a div at the same time? 如何防止多次单击按钮? - How can I prevent multiple button clicks? 如何创建一个 Javascript,在每次点击按钮时找到平均值 - How do I create a Javascript that finds average at every clicks on a button 在用户单击javascript / jquery中的按钮之前,如何防止元素加载? - How can I prevent an element to load until such time when the user clicks a button in javascript/jquery? 当有人单击带有 HTML、JS 或 Ajax 的按钮时,如何隐藏特定的部门? - How do I hide an specific division when someone clicks an button with HTML, JS or Ajax?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM