求助:insertAdjacentHTML提示"用于此操作的原始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> <div id="s1"> <li id="del_li"> 作者1: <input type="text" maxlength="30" size="10" name="author" /> <button onclick="return new_author()">添加作者</button> <button onclick="return del_author()">删除作者</button> </li> </div> <li> 通信作者: <input type="text" maxlength="30" size="10" name="communication_author" /> </li><ul></body>
<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: <input type="text" maxlength="30" size="10" name="author" /> <button onclick="return new_author()">添加作者</button> <button onclick="return del_author()">删除作者</button> </li> </div><ul></body>