-1

我想在单击更新按钮时显示一个窗口,此窗口应保持 3 秒,然后自动关闭结束执行更新操作。这是我的代码,但它不起作用

my $cScript = qq{

\$(document).ready(function(){
    var w;
    function closeWindow(){ 
        setTimeout(function() {
           w.close();
        }, 3000);
    }

    function createWindow(){
        //create the popup window.

        w=window.open("","",'width=200,height=100');

        // put something into the popup window
        try{
            w.document.write('<html><head></head><body><p>Updating...</p></body> <html>')
        }catch(err){
            //handle error here
        }
        closeWindow();

    });
};

print $q->script($cScript);
 }

HTML 表单:

 $cInput_form .= $q->image_button({
      -src =>  '/media/images/save_1.png',
      -class=>'btn btn-primary btn-large',
      -title => 'update', 
      -name => 'Update', 
      -value => $row_id,
      -onclick => "createWindow()"
});



print $q->fieldset ({-class => "ui-widget ui-widget-content"}, $cInput_form);

哪里有问题?

4

1 回答 1

2

演示:jsFiddle

JS:

var w;

createWindow();

function closeWindow() {
    setTimeout(function () {
        w.close();
    }, 3000);
}

function createWindow() {
    //create the popup window.
    var htmlText = "<p>Updating...</p>";
    w = window.open("", "", 'width=200,height=100');
    $(w.document.body).html(htmlText);
    closeWindow();
};
于 2013-07-28T19:48:19.950 回答