使用JavaScript的倒数计时器不适用于smarty

时间:2016-02-10 12:18:27

标签: javascript smarty

大家好我用Smarty()和JavaScript用倒数计时器制作一张表似乎一切正常但我不知道为什么我的倒数计时器只有一行结果 如果可能的话,请查看我的代码并告诉我我能做些什么,感谢所有程序员。祝你有美好的一天。

HTML:

function squareNumber(num){
    var squaredNumber = num * num;
    return squaredNumber;
    console.log("the square of " + num + " is " + squaredNumber);

}


function halfOf(num){
    var half = num / 2;
    return half;
    console.log(" half of  " + num + " is " + half);
}

function percentOf(num1, num2){

    var percent = (num1 / num2) * 100;
    return percent;
    console.log(num1 + " is  " + percent + " % of " + num2); 
}


function areaOfCircle(radius){
    var area = 3.14 * radius * radius;
    return area;
    console.log(" the area of a circle with radius of " + radius + " is " + area);

}

function doCrazyStuff(num){
    var halfy = halfOf(num);
    var squared = squareNumber(halfy);
    var area = areaOfCircle(squared);
    var result = percentOf(area, squared);

}

time.tpl:

<table class="table table-striped table-hover" id="datatable3" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>Avatar</th>
            <th>Player Name</th>
            <th>Game</th>
            <th>SS Shots</th>
            <th>BanTime Remaining</th>
            <th>Ban Reason</th>
        </tr>
    </thead>
    <tbody class="tb1">
    {foreach $bans as $ban}
        <tr class="tr1">
            <td class="count"></td>
            <td>{$ban.avatar}</td>
            <td>{$ban.name}</td>
            <td>{$ban.game}</td>
            <td>{$ban.ss}</td>
            <td>{include file="time.tpl"}</td>
            <td>{$ban.reason}</td>
        </tr>
    {/foreach}
    </tbody>
</table>

但是我的代码只有一行结果,为什么? 请参阅this screenshot

2 个答案:

答案 0 :(得分:0)

你的问题是setTimeout将函数指针作为参数,而不是带有函数名的字符串。

因此,请尝试:ID = setTimeout(update, 500);

有关详细信息,请查看docs。他们也有一个例子。

答案 1 :(得分:0)

  

document.getElementById("years")返回 元素,其ID为

在你的情况下,我只能看到一个id为 years 的元素。

如果要更改一组元素,可能需要为它们指定一个类名,然后对所有元素执行操作。

例如:

// If you keep *multiple rows* something like this (not sure about your table structure)
<tbody class="{$ban.userID}">
    <tr>
        <td><span class="years"></span></td>
        ...
    </tr>
    <tr>
        <td><span>years</span></td>
        ...
    </tr>

    <tr>
        <td><span class="years"></span></td>
        ...
    </tr>
    <tr>
        <td><span>years</span></td>
        ...
    </tr>

</tbody>
</table>


/** This would do the trick **/
document.getElementsByClassName("years").innerHTML = years;
// ...

`