2016-08-13 15 views

回答

1

HTML:

<div id="dynamicInput"> 
     <span class="glyphicon glyphicon-plus" onClick="addInput('dynamicInput');"></span> 
</div> 

的JavaScript:

function addInput(divName) 
{ 
      var newdiv = document.createElement('div'); 
      newdiv.innerHTML = "<input type='text' name='items[]'>"; 
      document.getElementById(divName).appendChild(newdiv);  
} 

你可以有数组项的这种方式。

并在你的控制器中保存这些。

foreach($items as $item) 
    { 
    if(!empty($item)) 
     {  
     $add=new Item(); //Item is the model 
     $add->name=$item; //saving item to name column 
     $add->save();  
     } 
    } 
+0

啊,是的,这将是完美的。感谢您的帮助! –

1

你可以做到这一点使用AJAX(jQuery的)

$.ajax({ 
    url: 'your/array/route', 
    type: 'GET', 
    success: function(data) { 

     if(data.result != null) { 
      $.each(data.result, function(i, v) { 
       $("#form").append('<input type="text" value="'+v.your_value+'">'); 
      ); 
     } 
    } 
}); 
相关问题