两段源代码的顺序不一样居然导致运行结果不一样。请各位帮忙指出问题。
源代码如下:<script type="text/javascript">
//添加作者
var current=1; 
function new_author() 

old=current; 
current=current + 1;
//设置插入的内容 
str1="<div id=s" + current + "><li>作者" + current + "<input type=text maxlength=10 size=10 name=author/></li></div>";
strX="s"+ old; 
eval("document.all." + strX + ".insertAdjacentHTML(\"AfterEnd\",str1)"); 
}
</script></head>
<body>
<ul>
<div id="s1">
<li id="del_li">
作者1:&nbsp;&nbsp;&nbsp;
<input type="text"  maxlength="30" size="10"  name="author" />
<button onclick="return new_author()">添加作者</button>
&nbsp;&nbsp;
<button onclick="return del_author()">删除作者</button>
</li>
</div>    <li>
通信作者:
<input type="text"  maxlength="30" size="10"  name="communication_author" />
</li>
<ul>
</body>这段代码运行没有任何问题。但是把<li>通信作者...</li>这段代码放到<div id="s1">...</div>这段代码前面去,运行时出现错误:用于此项操作的原始HTML无效。<script type="text/javascript">
//添加作者
var current=1; 
function new_author() 

old=current; 
current=current + 1;
//设置插入的内容 
str1="<div id=s" + current + "><li>作者" + current + "<input type=text maxlength=10 size=10 name=author/></li></div>";
strX="s"+ old; 
eval("document.all." + strX + ".insertAdjacentHTML(\"AfterEnd\",str1)"); 
}
</script></head>
<body>
<ul>
    <li>
通信作者:
<input type="text"  maxlength="30" size="10"  name="communication_author" />
</li> <div id="s1">
<li id="del_li">
作者1:&nbsp;&nbsp;&nbsp;
<input type="text"  maxlength="30" size="10"  name="author" />
<button onclick="return new_author()">添加作者</button>
&nbsp;&nbsp;
<button onclick="return del_author()">删除作者</button>
</li>
</div>
<ul>
</body>请问这是为什么?
我的环境是win xp sp2 + IE6。

解决方案 »

  1.   

    你把人家的DOM结构更改了呗= =.
    你代码给的也不全 不知道怎么帮你改
      

  2.   

    我的问题已经得到彻底解决了,多谢你的回复!
    http://www.cs.tut.fi/~jkorpela/html/nesting.html
      

  3.   

    我也有这样的问题,在Ext中。if(this.toolTip){
    this.toolTip = new Ext.ToolTip({
    target:this.getEl(),
    autoHide:true,
    anchor: 'bottom',
    showDelay:100,
    anchorToTarget:true,
    trackMouse: true,
    renderTo: document.body,
    html:' ',
    listeners: { 
    scope:this,
    'beforeshow': function(tip) {
    //alert(this.getValue());
    tip.body.dom.innerHTML = this.getValue();
    },
    'show': function(tip){
    if(tip.body.dom.innerHTML.trim() == '' || !this.toolTip){
    tip.hide();
    }
    }
    }
    });
    }
      

  4.   

    不知道为什么,总是报 “用于此操作项的原始HTML无效”。在FF下没事,IE下一直报。纠结啊~~~