<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>无标题文档 </title> <script language="javascript" type="text/javascript"> 
function openIF(){ 
var win = window.open("http://www.hao123.com","fi","");  
alert("window.open已经执行完毕!!!");

</script> 
</head> 
<body> <iframe width="200px" height="200" name="fi"> </iframe> 
<p> <hr> 
<form > 
<input type="submit" value="提交" onclick="openIF()"> 
</form> 
</body> 
</html> 上面的代码显示window.open已经执行完毕,但是却没有任何效果。
如果把type="submit"改为type="button"就可以,请问这是为什么?

解决方案 »

  1.   

    以上代码copy后,直接alert出"window.open已经执行完毕!!!";
      

  2.   

    submit 执行完后会提交,然后刷新
    这样弄就OK(禁止提交)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档 </title><script language="javascript" type="text/javascript">
    function openIF(){
    var win = window.open("http://www.hao123.com","fi","");
    alert("window.open已经执行完毕!!!");
    return false
    }
    </script>
    </head>
    <body> <iframe width="200px" height="200" name="fi"> </iframe>
    <p> <hr>
    <form >
    <input type="submit" value="提交" onclick="return openIF()">
    </form>
    </body>
    </html>
      

  3.   

    是在alert以后刷新的,准确的说是在方法执行以后刷新,因为提交了表单返回false以后不提交表单,所以和button执行结果一样
      

  4.   

    哦,明白lz的意思 了lz可以到Firefox下就可以看到效果了,alert的时候iframe会显示hao123,然后就刷没了
      

  5.   

    如果是type是submit,你这个函数调用不应该写在这里的onclick上,应该写在form的onsubmit上。
      

  6.   

    form刷新的是整个页面啊?
    去掉form标签也可以运行的
      

  7.   

    是的,你尝试下面代码就可以了,如果不用form的话也不会提交
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
            <title>无标题文档 </title>        <script language="javascript" type="text/javascript">
                function openIF(){
                    var win = window.open("http://www.baidu.com","fi","");
                    document.getElementById("test").innerHTML="xxxx";
                    alert("window.open已经执行完毕!!!");
                    return true
                }
            </script>
        </head>
        <body> <iframe width="200px" height="200" name="fi"> </iframe>
            <p> <hr>
                    <form>
                    <input type="submit" value="提交" onclick=" openIF()">
                        </form>
                        <div id="test">asdasd</div>
                        </body>
                        </html>