2

我有一个 jQuery 弹出表单来动态添加输入字段,我想将此表单值作为隐藏输入或隐藏数组提交到父页面,但我无法将弹出表单的值放入数组中!这是我的弹出表单代码

    <html>
    <form method="post" action="register" name="myform" id="myform" style="margin-left:10px" >  

    <div id="newlink">  
    <div>  
<br>
    <input type="text" id="phone[]" name="phone[]"  placeholder="Telephone" required>  
    <input type="text" id="mobile[]" name="mobile[]"  placeholder="Mobile" required> 
    </div>  


    </div>  
    <p id="addnew">  
    <a href="javascript:new_fields()" class="btn btn-success" style="margin-left:10px">Add New     </a>  
    </p>  
    <p>  
    <br>  
    <button data-dismiss="modal" aria-hidden="true">Save Values</button> 
    </p>  
    </form>  
    <div id="newinput" style="display:none">  
    <div>  
    <br>
    <input type="text" name="phone[]" value="" placeholder="Telephone" required>  
    <input type="text" name="mobile[]" value="" placeholder="Mobile" required> 
    </div>  
    </div> 

这是我添加动态输入字段的脚本

    <script>
    var ct = 1;  

    function new_fields()  
    {  
    ct++;  
    var div1 = document.createElement('div');  
    div1.id = ct;  

    var delLink = '<div style="float:right;margin-right:110px;margin-top:-40px" class="btn btn-danger"><a href="javascript:delIt('+ ct +')" style="color:#FFFFFF;">Del</a></div>';  

    div1.innerHTML = document.getElementById('newinput').innerHTML + delLink;  

    document.getElementById('newlink').appendChild(div1);  

    }  
// function to delete the newly added set of elements  
  function delIt(eleId)  
    {  
    d = document;  

    var ele = d.getElementById(eleId);  

    var parentEle = d.getElementById('newlink');  

    parentEle.removeChild(ele);  

     }  
    </script>  

这是从弹出窗口将值发送到父页面的脚本

   <script>
   $(document).ready(function(){
   $("button").click(function(){
   x=$("#myform").serializeArray();
   $("#results").append(field.name + ":" + field.value + " ");
   });
   });
   });
   </script>

但结果是这样的:

   phone[]:20304050 mobile[]:7864435454 
4

0 回答 0