0

我有一个计量器,每次单击按钮时都会刷新并获取随机数据。

我的问题是如何在不单击按钮的情况下执行此操作,我希望它每 5 秒自动刷新一次。

 <div id="gg1" class="gauge">
</div>
<a href="#" id="gg1_refresh" class="button grey">Random Refresh</a>
<script>
    var gg1 = new JustGage({
        id: "gg1",
        donut: 1,
        title: "BARTOW",
        titleFontColor: "#000000",
        value: 95.7,
        min: 0,
        max: 100,           
        labelFontColor: "#000000",
        humanFriendlyDecimal: 1,
        decimals: 1,
        symbol: "%",
        refreshAnimationType: "bounce",
        gaugeWidthScale: 0.6,
        customSectors: [{
            color: "#ff0000",
            lo: 0,
            hi: 79
        }, {
            color: "#ffa500",
            lo: 80,
            hi: 89
        }, {
            color: "#1eae1e",
            lo: 90,
            hi: 100
        }],
        counter: true
    });
    $(document).ready(function () {
        $('#gg1_refresh').bind('click', function () {
            gg1.refresh(getRandomInt(0, 100));
            return false;

        });
    });
</script>
4

2 回答 2

2

您需要使用setInterval每 5 秒调用一次函数。

您将需要创建一个包含代码的函数

gg1.refresh(getRandomInt(0, 100));

然后在单击事件处理程序中使用 setInterval 函数来调用您在上面创建的函数。

于 2013-11-25T13:54:39.547 回答
1

查看以下内容,根据@thenewseattle 的评论进行编辑。

<script type="text/javascript">
    function refreshDiv() {
       gg1.refresh(getRandomInt(0, 100));
    }
    $(document).ready(function () { setInterval(refreshDiv, 5000); });
</script>
于 2013-11-25T13:53:26.813 回答