意思是你不能给动态生成的元素设置name,只能在创建的时候设置name。

解决方案 »

  1.   

    wangxj0600(wamgxj0600):什么叫动态生成的元素,能否举例说明一下,谢谢!
      

  2.   

    这里run time是即时生成的意思,这里这个<A NAME='AnchorName'></A>并不是页面中本来存在的,是使用createElement后才生成的,它是动态生成的元素The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.这句话是说你不能在使用createElement创建元素后再给它增加name属性,必须在使用createElement创建改元素的时候就加上,例如它的例子document.createElement("<A NAME='AnchorName'></A>");
      

  3.   

    但是,下面的网页代码可以运行。为什么?<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <SELECT ID="oSelect">
      <OPTION VALUE="1">One</OPTION>
    </SELECT><SCRIPT>
    var oOption = document.createElement("OPTION");
    oSelect.add(oOption);
    oOption.innerText = "Two";
    oOption.value = "2";
    oOption.name = "qaz";
    alert(document.body.outerHTML);
    </SCRIPT>
    </body>
    </html>