我希望在成功提交表单时,应显示一条消息,并在5秒后淡出。
我编写的代码无效
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery- `enter code here`latest.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form method='post'>
<input type='text' name='txt'></input>
<button type='submit' id='but1'>CLICK ME</button>
<div id=deletesuccess > hiiiiiiiiiii </div>
</form>
<script type="text/javascript">
$( "form" ).submit(function( event ) {
$('#deletesuccess').delay(1000).fadeOut();
});
</script>
</body>
</html>
答案 0 :(得分:0)
试试这个:
$( "form" ).submit(function( event ) {
$('#deletesuccess').fadeIn();
setTimeout(function(){
$('#deletesuccess').fadeOut();
}, 5000);
return false;
});
答案 1 :(得分:0)
您必须阻止本机表单提交五秒钟,然后触发它
$( "form" ).submit(function( event ) {
event.preventDefault();
var self = this;
$('#deletesuccess').delay(1000).fadeOut(4000, function() {
self.submit();
});
});