有没有办法自动订购一组clickCount

时间:2011-09-11 15:58:02

标签: javascript html click-counting

在我的编码中,我将有3个clickCounts全部垂直,我想知道是否有这样的代码自动将最高的clickCount移动到顶部:

这是我到目前为止的代码:

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script type="text/javascript">

function countClicks() {
var x = 0;


x += 1
document.getElementById( "counting" ).innerHTML = 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" ).innerHTML = x;

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

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


</script>

<script type="text/javascript">

function countClicks2() {
var x = 0;


x += 1
document.getElementById( "counting2" ).innerHTML = x;

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

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


</script>


</head>
<body>

<div style="margin-left:100px;">
<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();" />
<div id="counting"></div>

<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();" />
<div id="counting1"></div>

<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 countClicks2();" />
<div id="counting2"></div>
</div>

1 个答案:

答案 0 :(得分:0)

DOM可以通过任意标准进行操作。如果你用适当的idd(或跨度)包裹每个部分,你可以将它从一个地方移除并像往常一样放在另一个地方。如果它是一个有序列表,IMO,它应该存在于一个实际的有序列表中,虽然这不是绝对必要的,但它只是更加语义化。