自排序投票系统

发布于 2024-12-04 01:07:30 字数 1603 浏览 1 评论 0原文

我需要一些基于 javascript 的代码来帮助我的投票系统。基本上,我正在努力弄清楚如何让我的收到投票的项目自行进入订单状态。因此,如果一个项目有 52 票,而下面的项目获得 2 票,达到 54 票,我希望它与上面的 1 票交换位置。

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vote!</title>


<style>
#counting {
font-family:avante;
font-size:20px;
border:0px;
}

#counting1 {
font-family:avante;
font-size:20px;
border:0px;
}

</style>



<script type="text/javascript">

function countClicks() {
var x = 0;


x += 1
document.getElementById( "counting" ).value = x;

var clickLimit = 1; //Max number of clicks
if(x>=clickLimit) {

            }
else
{
    ClickCount++;
    return true;
}
}

</script>

<script type="text/javascript">

function countClicks1() {
var x = 0;


x += 1
document.getElementById( "counting1" ).value = x;

var clickLimit = 1; //Max number of clicks
if(x>=clickLimit) {

            }
else
{
    ClickCount++;
    return true;
}
}

</script>


</head>
<body>


<img src="../Pictures/BWS + L.A +KUSH/Game.RED_Album_Cover.jpg" alt="red album"><br>
<input type="button" value="VOTE" name="clickOnce" onclick="return countClicks();" />        <br>
<input id="counting" type="text">
<br>
<br>
<img src="../Pictures/BWS + L.A +KUSH/Game.RED_Album_Cover.jpg" alt="red album"><br>
<input type="button" value="VOTE" name="clickOnce" onclick="return countClicks1();" />   <br>
<input id="counting1" type="text">


</body>

</html>

I need some javascript based code that can help my voting system. Basically I am struggling to work out how to get my items that receive votes to move into order by itself LIVE. So If an item had 52 votes and the item below gained 2 votes to make 54 I would like it to swap places with the 1 above.

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vote!</title>


<style>
#counting {
font-family:avante;
font-size:20px;
border:0px;
}

#counting1 {
font-family:avante;
font-size:20px;
border:0px;
}

</style>



<script type="text/javascript">

function countClicks() {
var x = 0;


x += 1
document.getElementById( "counting" ).value = x;

var clickLimit = 1; //Max number of clicks
if(x>=clickLimit) {

            }
else
{
    ClickCount++;
    return true;
}
}

</script>

<script type="text/javascript">

function countClicks1() {
var x = 0;


x += 1
document.getElementById( "counting1" ).value = x;

var clickLimit = 1; //Max number of clicks
if(x>=clickLimit) {

            }
else
{
    ClickCount++;
    return true;
}
}

</script>


</head>
<body>


<img src="../Pictures/BWS + L.A +KUSH/Game.RED_Album_Cover.jpg" alt="red album"><br>
<input type="button" value="VOTE" name="clickOnce" onclick="return countClicks();" />        <br>
<input id="counting" type="text">
<br>
<br>
<img src="../Pictures/BWS + L.A +KUSH/Game.RED_Album_Cover.jpg" alt="red album"><br>
<input type="button" value="VOTE" name="clickOnce" onclick="return countClicks1();" />   <br>
<input id="counting1" type="text">


</body>

</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凹づ凸ル 2024-12-11 01:07:30

由于投票(大概)存储在服务器上,因此您需要定期请求更新的数据(例如使用 XHR )。显然,这需要您有一个服务器端程序来生成数据(JSON 是数据格式的不错选择) 。获得数据后,您可以使用它来决定 HTML 元素应显示的顺序,并使用 移动它们insertBeforeappendChild

Since the votes are (presumably) stored on the server, you will need to request updated data periodically (e.g. using XHR). Obviously, this will require that you have a server side program to generate the data (JSON is a good choice for the data format). Once you have the data, you can use it to decide what order your HTML elements should appear in and move them around with insertBefore and appendChild

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文