如何使用onclick事件倒计时(gieson)?

时间:2014-08-08 09:38:07

标签: javascript

gieson倒计时的示例用法如下。没关系。

    <body>
        <script src="countdown.js" type="text/javascript"></script>
        <script type="application/javascript">
                var myCountdown2 = new Countdown({time: 30000, width:200, height:80, rangeHi:"hour"});
        </script>
    </body>

enter image description here

我想在按钮onclick时开始倒计时。但不行。

<body>
    <script src="countdown.js" type="text/javascript"></script>
    <script type="application/javascript">
        var myCountdown2;
        function startCount() {
            myCountdown2 = new Countdown({time: 30000, width:200, height:80, rangeHi:"hour"});
        }
    </script>
    <input type="button" value="start" onclick="startCount();"/>
</body>     

enter image description here

我该如何解决?我没有javascript经验。

错误:

Error in parsing value for 'size'.  Declaration dropped.

2 个答案:

答案 0 :(得分:0)

尝试将myCountDown2保存在全局范围内。

答案 1 :(得分:0)

我测试了它并且工作正常

<body style="background-color:#EDEDED">

<p onClick="return countIt();">Example 1 - Time until April 1, 2016</p>

<!-- START COUNTDOWN -->
<script src="countdown.js" type="text/javascript"></script>
<script type="application/javascript">
function countIt(){
var myCountdownTest = new Countdown({
                                    time: 30000, width:200, height:80, rangeHi:"hour"
                                    });


}
</script>