window.onload不适用于计数器页面

时间:2016-04-26 07:08:04

标签: javascript perl

我不明白!为什么这段代码不起作用? window.onload不能兼具双重功能。我该怎么做这个代码呢?

Perl没问题。但Javascript是错误的。我需要Javascript的帮助。

的Perl:

print $lqcgi->td({ -class => 'navItemText', -align => 'left'}, '<script> document.write("refresh in <strong><span id=\"counter\"></span></strong> seconds")</script></td></tr>' )

print "<script>document.write('<p><small>You will be redirected to main page in <strong><span id=\"a_reload\"></span></strong> sec.</small></p>')</script>";

使用Javascript:

   var Time = 60;
    var Counter = zaehler;
    function zaehler(){
        if (Time > 0) {
            Time --;
            document.getElementById('counter').innerHTML = Time;
            setTimeout("zaehler()",1000);
        }
        else {
            window.location.reload(true);
        }
    }
    window.onload = Counter;

    function a_confirm(){
        var x = confirm("Are you sure to Confirmation?");
        if (x == true){
            return true;
        }
        else{
            return false;
        }
    }

    var Time_2 = 5;
    var Counter_2 = c_reload
    function c_reload(){
        if (Time_2 > 0) {
            Time_2 --;
            document.getElementById('a_reload').innerHTML = Time_2;
            setTimeout("c_reload()", 1000);
        }
        else{
            window.history.back(-1);
        }
    }
    window.onload = Counter_2;

1 个答案:

答案 0 :(得分:0)

var Counter = function (){

应该解决你的问题。目前,您在创建引用之前会分配一个引用( zaehler )。会是

my $Counter = $zaehler;
my $zaehler = sub {
...

在Perl。