我有这个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秒后消失。
答案 0 :(得分: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
答案 1 :(得分:0)
您可以使用delay()
$('divtoremove').delay(5000).fadeOut('fast');
答案 2 :(得分:0)
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');});
}
}
您也可以使用detach并稍后将其重新附加到DOM。