在IE中Anchor的name属性只能以传统模式定义,运行时这个属性是只读的。在其他浏览器可以

解决方案 »

  1.   

    IE 中 anchor 的name 是只读的,
    IE 中就直接使用 innerHTML 创建吧content.innerHTML = "<a name='toc'>toc</a>";
      

  2.   

    anchor.name创建也不行的,看样子只能用 晓风残月的方法了,谢谢各位解答,明天结贴
      

  3.   

    什么概念?
    打开页面用不了JS?
    这样就可以用了。<body>
    <script type="text/javascript">
    function create(){
    var content = document.createElement("div");
    var anchor = document.createElement("a");
    anchor.setAttribute("name","Toc");
    anchor.appendChild(document.createTextNode("Test anchor"));
    content.appendChild(anchor);
    document.body.appendChild(content);
    }
    function print() {
    var newWin = window.open("","console");
    var html = document.body.innerHTML;
    var p = new RegExp("<s" + "cript[^>]*>((?:\r|\n|.)*?)<\/s" + "cript>", "i");
    var script = html.match(p)[0];
    newWin.document.write(html.replace(p, ""), script);

    }
    </script>
    <H1>Test</H1>
    <button onclick="create();">Test</button>
    <button onclick="print();">View</button>
    </body>
    在view按钮打开的窗体的显示的html:
    <H1>Test</H1><BUTTON onclick="create()">Test</BUTTON><BUTTON onclick=print();>View</BUTTON> 
    <DIV><A>Test anchor</A></DIV>
      

  4.   

    ls上可能看错我的意思,我只是想动态创建锚点,不是用不了不是JS,view只示显示我操作的document页的html代码,呵
      

  5.   

    IE中可以这样var anchor=document.createElement("<a name='abc'>");