动态添加文本框

  <script>

    var num=1;
function AddInput()

    var str="";
    str+="<input  type=\"text\" id=\"tel"+num+"\">";
    window.dvInput.innerHTML+=str;
    num++;
}

function getall()
{
for(i=1;i<num;i++)
{
alert(document.getElementById('tel' + num).value);
     document.getElementById("hidValue").value += document.getElementById('tel' + num).value+"|";

}
   alert(document.getElementById("hidValue").value);
}

        </script>

        <input id="Button2" type="button" onclick="AddInput();" value="添加" />
        <asp:Button ID="Button1" runat="server" OnClientClick=" getall();" Text="提交" />
        <div id="dvInput">
        </div>
        <input type="hidden" id="hidValue" />

-----------------------------------------------------------------------------------------------------------------------------------------------

<script type="text/javascript">

//save method
function modifySave() {
    if(validate()){
        var num = 0;
        var str="";
        var arr = new Array();
        if($("#documentClaim option").length>0) {
            $("#documentClaim option").each(function(){
                str+="<input  name=\"masterPolicyDocumentsManagementTabDto.documentClaimDocumentCodesArr\" type=\"hidden\" id=\"documentClaimDocumentCodesArr"+num+"\">";
                arr[num] = $(this).val();
                num++;
            })
        }
       
        Output.innerHTML=str;
        for(var i = 0; i < num; i++ ){
            $("#documentClaimDocumentCodesArr"+i).val(arr[i]);
        }
        confirmSubmitForm();
    }
}

</script>

 

<p id="Output"></p>

 

 

你可能感兴趣的:(文本框)