用户点提交按钮之后,我想在页面中显示一张图片,几秒钟之后再提交:<script type="text/javascript">
function check_exchange(form) {
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
return false;
}
else {
setTimeout("fun2()",5000);
return confirm('您确定联系方式正确并抽取此礼品吗?');
}
function fun2(){
document.getElementById('loading').style.display=='block';
document.getElementById('message').style.display=='none';
}
}
</script>但是根本没用。点“提交”按钮马上就提交了,根本没有等待啊
function check_exchange(form) {
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
return false;
}
else {
setTimeout("fun2()",5000);
return confirm('您确定联系方式正确并抽取此礼品吗?');
}
function fun2(){
document.getElementById('loading').style.display=='block';
document.getElementById('message').style.display=='none';
}
}
</script>但是根本没用。点“提交”按钮马上就提交了,根本没有等待啊
把 form.submit()放到fun2中
function check_exchange(form) {
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
return false;
}
else {
if( confirm('您确定联系方式正确并抽取此礼品吗?') ){
document.getElementById('loading').style.display=='block';
document.getElementById('message').style.display=='none';
setTimeout(function(){ form.submit(); }, 5000);
}
return false;
}
}
</script>
document.getElementById('message').style.display=='none';等号?
HTML code<script type="text/javascript">
function check_exchange(form) {
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
r……
[/Quote]
function check_exchange(form) {
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
return false;
}
else {
if( confirm('您确定联系方式正确并抽取此礼品吗?') ){
document.getElementById('loading').style.display='block';
document.getElementById('message').style.display='none';
setTimeout(function(){ form.submit();}, 5000);
}
else
{
return false;
}
}
</script>
现在的问题是,loading 图片根本没显示5秒,刷一下就过去了
var breturn=1;
function check_exchange(forms){
form = document.exchangefrm;
if(form.linkman.value== '') {
alert('未填写联系人。');
breturn=1;
return false;
}else {
if(breturn){
if(confirm('您确定联系方式正确并抽取此礼品吗?')){
document.getElementById('loading').style.display='block';
document.getElementById('message').style.display='none';
setTimeout(function(){breturn=0;form.submit();}, 5000);
return false;
}else{
breturn=1;
return false;
}
}else{
return true;
}
}
}
</script>
form = document.exchangefrm;
if(form.linkman.value.trim() == '') {
alert('未填写联系人。');
return false;
}
else {
return false; //问题大概在这里,必须要先设置提交功能失效,否则马上就执行提交了
setTimeout("fun2()",5000);
return confirm('您确定联系方式正确并抽取此礼品吗?');
}
}然后在fun2()里面加上提交就可以了form.submit();
document.getElementById('loading').style.display='none';
document.getElementById('message').style.displa='';
if (confirm('您确定联系方式正确并抽取此礼品吗?')){
alert(1);
window.setTimeout("fun2()",50000);
}
}
function fun2(){
document.getElementById('loading').style.display='';
document.getElementById('message').style.displa='none';
frm.submit();
bb();
document.getElementById('loading').style.display='none';
document.getElementById('message').style.displa='';
if (confirm('您确定联系方式正确并抽取此礼品吗?')){
window.setTimeout("fun2()",50000);
}
}
function fun2(){
document.getElementById('loading').style.display='';
document.getElementById('message').style.displa='none';
frm.submit(); //在form中要指定跳转的页面地址
// locaion.href=...url;
// 或指定跳转的页面地址
}
bb();
原理是一样的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function check(obj) {
var _form = document.getElementById('testForm');
var _value = document.getElementById('key').value;
var _flag = false;
if(_value != '') {
_flag = true;
}
if(_flag) {
setTimeout(function(){_form.submit();}, 5000);
}
return false;
}
</script>
<form id='testForm' method="post" action="#testForm" onsubmit="return check()">
<input type="text" name="key" id='key' />
<input type="submit" value="submit" />
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<form method="post" action="index.php?ac=exchange" id="exchangefrm" name="exchangefrm" onsubmit="return check_exchange(this.form);">
<div id="loading" style="display:none">loading</div>
<div id="message">message</div>
<input type="text" name="linkman" id="linkman" />
<input type="button" value="2222222222" />
<input type="submit" name="btnsubmit" id="btnsubmit" />
</form>
<script type="text/javascript">
var breturn=1;
function check_exchange(forms){
form = document.exchangefrm;
if(form.linkman.value== '') {
alert('未填写联系人。');
breturn=1;
return false;
}else {
if(breturn){
if(confirm('您确定联系方式正确并抽取此礼品吗?')){
document.getElementById('loading').style.display='block';
document.getElementById('message').style.display='none';
setTimeout(function(){breturn=0;form.submit();}, 5000);
return false;
}else{
breturn=1;
return false;
}
}else{
return true;
}
}
}
</script>
</body>
</html>