日期:2014-05-16  浏览次数:20429 次

js动态添加文本框后前面文本框里面内容被清除
<input type="text" name="txtAddr" maxlength="100"/><a href="javascript:void(0);" onclick="addInput1();">添加</a>


function addInput1()
{
document.getElementById("txtAddr").innerHTML=document.getElementById("txtAddr").innerHTML+"\<input type=\"text\" name=\"txtAddr\" maxlength=\"100\"/>"
}


IE在输入一个文本框后点击后面的添加是没有问题的。但是火狐或者Google的话,点击添加后前面文本框输入的东西也没有了,这个怎么破?
js动态添加

------解决方案--------------------
你是要在一个文本框里加一个文本框?
------解决方案--------------------
<div id="txtAddr"><input type="text" name="txtAddr" maxlength="100"/></div>
<a href="javascript:void(0);" onclick="addInput1();">添加</a>
<script type="text/javascript">

function addInput1()
{
var input = document.createElement("input");
input.type="text";
input.name="txtAddr";
input.maxlength="100";
document.getElementById("txtAddr").appendChild(input);
}
</script>