1

我有这个 AJAX 表单:

function form(){

        var icao = document.getElementById('icao').value;
        var name = document.getElementById('name').value;
        var weightempty = document.getElementById('weightempty').value;
        var weightfull = document.getElementById('weightfull').value;
        var cargofull = document.getElementById('cargofull').value;
        var cruisespeed = document.getElementById('cruisespeed').value;
        var range = document.getElementById('range').value;
        var price = document.getElementById('price').value;
        var firstclassseats = document.getElementById('firstclassseats').value;
        var businessclassseats = document.getElementById('businessclassseats').value;
        var economyclassseats = document.getElementById('economyclassseats').value;
        ajax.open("POST","new_aircraft_process.php",true);
        ajax.onreadystatechange=function(){
            if(ajax.readyState==4)
            {
            var respuesta=ajax.responseText;


            document.getElementById('result').innerHTML=ajax.responseText;
            $("#newaircraftdialog").dialog('close');


            refreshTable(function(){$("#loadingdialog").dialog('close');});
            }
        }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("icao="+icao+"&name="+name+"&weightempty="+weightempty+"&weightfull="+weightfull+"&cargofull="+cargofull+"&cruisespeed="+cruisespeed+"&range="+range+"&price="+price+"&firstclassseats="+firstclassseats+"&businessclassseats="+businessclassseats+"&economyclassseats="+economyclassseats);
    $("#loadingdialog").dialog('open');
    }

我想要的是在结果 div 中显示结果时(它是一个显示“成功表单”的文本),它是否仅可见 5 秒然后消失。我找到了各种方法,但不想删除 div。因为如果我想再次制作表单,结果将不得不再次显示在 div 中,并在 5 秒后消失。

4

3 回答 3

3
$('.myDiv').fadeIn(); // Show the div to start.
// All your other code here.
setTimeout(function() { $('.myDiv').fadeOut() }, 5000); // hide the div after we're done
于 2013-01-16T17:51:20.193 回答
0

您可以使用delay()

$('divtoremove').delay(5000).fadeOut('fast');
于 2013-01-16T17:53:46.743 回答
0

您可以隐藏div 并在稍后重新提交表单时显示它。

ajax.onreadystatechange=function(){
    if(ajax.readyState==4)
    {
        var respuesta=ajax.responseText;


        var $result = $('#result');
        $result.html(ajax.responseText);
        $result.show();
        setTimeout(function() { $result.hide() }, 5000);
        $("#newaircraftdialog").dialog('close');


        refreshTable(function(){$("#loadingdialog").dialog('close');});
    }
}

您也可以稍后使用分离并将其重新附加到 DOM。

于 2013-01-16T17:54:12.597 回答