用户点提交按钮之后,我想在页面中显示一张图片,几秒钟之后再提交:<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>但是根本没用。点“提交”按钮马上就提交了,根本没有等待啊

解决方案 »

  1.   

    settimeout 后的语句还是会立即执行的可以先return false 
    把 form.submit()放到fun2中
      

  2.   

    有调用setTimout这个函数,之中的函数当然会马上调用啦
      

  3.   

    这样呢?<script type="text/javascript">
    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>
      

  4.   

    没显示出loading的图片,5秒之后,页面刷新了一下,地址栏变了,但是网页内容没变
      

  5.   

    document.getElementById('loading').style.display=='block';
    document.getElementById('message').style.display=='none';等号?
      

  6.   

    sdfsdfsdfs
    HTML code<script type="text/javascript">
    function check_exchange(form) {
        form = document.exchangefrm;
        if(form.linkman.value.trim() == '') {
            alert('未填写联系人。');
            r……
    [/Quote]
      

  7.   

    <form method="post" action="index.php?ac=exchange" name="exchangefrm" onsubmit="return check_exchange(this);"><script type="text/javascript">
    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秒,刷一下就过去了
      

  8.   

    按钮不要做submit类型,点击按钮先触发事件A显示图片,然后事件A里面再用setTimeout去触发事件B做表单提交
      

  9.   

    2遍啊,这个分也给我吧!<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>
      

  10.   

    你是用的这个吗?onSubmit="return check_exchange(X)"function check_exchange(form) {
    form = document.exchangefrm;
    if(form.linkman.value.trim() == '') {
    alert('未填写联系人。');
    return false;
    }  
    else {
    return false;  //问题大概在这里,必须要先设置提交功能失效,否则马上就执行提交了
    setTimeout("fun2()",5000);
    return confirm('您确定联系方式正确并抽取此礼品吗?');
    }
    }然后在fun2()里面加上提交就可以了form.submit();
      

  11.   

    不好意思,上面的“return false; //问题大概在这里,必须要先设置提交功能失效,否则马上就执行提交了”挪到后面去,否则不工作了
      

  12.   

    你这个应该不是SetTimeout()的问题,请你在submit 的触发事件前加上 return fn();
      

  13.   

    function bb(){
    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();
      

  14.   

    function 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();
      

  15.   

    分数不在多,有就行!
    原理是一样的。
    <!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>
      

  16.   


    <!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>