试试用 插入 HTML 代码的方式吧.这个应该是IE的BUG
你用  document.body.innerHTML +='<iFrame id="test" name="test" src=""></iFrame>';
 准保就好了.

解决方案 »

  1.   

    对于ie,iframe标签的name是readonly的,不过iframe里的window对象的name是可以改变的:
    以下代码演示ie的情况:
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head>
    <title> new document </title>
    <meta name="generator" content="Microsoft FrontPage 4.0">
    <script language="JavaScript">
    <!--
    window.onload = function(){
    var iframe = document.createElement('iframe');
    iframe.name="aaa";
    alert(iframe.outerHTML);
    document.body.appendChild(iframe);
    document.frames[0].name="test";
    }
    //-->
    </script>
    </head><body>
    <form action="test.asp" target="test" onsubmit="alert(document.getElementsByName('test').length);">
    <input type="submit" value="do"/>
    </form>
    </body>
    </html>
      

  2.   

    很多标签的name属性都是readonly的,ie的帮助文件里通常会作特别说明,如果想赋标签的name,就用innerHTML来做。
    另外,ie也可以通过如下来create带名字的标签:
    var iframe = document.createElement('<iframe name="test">');
      

  3.   

    iframe.name="test";//赋值不成功
    document.frames[0].name="test";//赋值成功原因并不是“对于ie,iframe标签的name是readonly的”
    因为IE中是这样说明的:name
    --------------------------------------------------------------------------------Description
    Specifies the name of a window or the frame so it can be targeted from links in other documents. Syntax
    object.name[ = sName] //以这种语法表示的是可读写的属性。Settings
    This read/write property takes either a window name or frame name, or one of these special valuesRes
    An exception to the rule, the window keyword must be used to access the name property.
      

  4.   

    Res 备注
    An exception to the rule, the window keyword must be used to access the name property.
    意思就是必须通过window关键字(也就是window对象)来访问window/frame的name属性。
      

  5.   

    一个是window对象的name,一个是window标签的name,
    尽管在某些用途上,二者有互通的情况,
    但是它们不是一样的,
    IE的帮助文件里对这一点有些含糊。示例代码里,每次点do,alert出来的都是0,
    可见,<iframe>的name并没有改变,是只iframe里window的name有了改变.
      

  6.   

    一个是window对象的name,一个是window标签的name,
    --->>>
    一个是window对象的name,一个是iframe标签的name,