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

通过js新增的text如何在新增text文本框时保留原来text的值
以这个为例子

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
    function addObj()
    {
        var inputText = "<input type='text' name='text' />";
        var html=document.getElementById("div1");
        html.innerHTML = html.innerHTML+inputText;
    }
</script>
</head>
 
<body>
<form id="from1" action="" method="get">
<div id="div1">
     
</div>
<input type="button" value="添加文本框"  onclick="addObj()" />
<input type="submit"  value="提交"/>
</form>
</body>
</html>

按下"添加文本框"后,原来文本框中输入的值就消失了,何解?
另外还有一个问题,用的是asp,通过request("text")获取到的值都是用“,”隔开,如何换成“&&”这样的符号隔开?

------解决方案--------------------
引用:

html.appendChild(inputText)

var html=document.getElementById("div1");
            var input = document.createElement("INPUT");
            input.setAttribute("name","text");
            input.setAttribute("type","text");
            html.appendChild(input);

------解决方案--------------------

    function addObj() {
        var input = document.createElement('input');
        input.name  = 'text';
        input.type = 'text';
        document.getElementById("div1").appendChild(input)
    }


同名的name都是用“,”分隔开每个项目的,要用&&分隔,asp replace一下
text=replace(request("text"),",","&&")


------解决方案---