[英]Issue with javascript repeating div in a form?
我正在嘗試制作一種僅重復表格的一部分的表格。 建議我在這里使用JavaScript。 我的當前代碼不斷出現錯誤。 請幫忙。
形式如下:
{{ Form::open() }}
<div class="repeating">
<input type="number" name="part_number" placeholder="Part Number" />
<input type="number" name="quantity" placeholder="Quantity" />
<input type="number" name="annual_usage" placeholder="Annual Usage" />
</div>
<input type="submit" value="Add Part" />
<input type="textarea" name="comment" placeholder="Comment" />
<input type="text" name="shippingaddress" placeholder="Shipping Address" />
<input type="text" name="project_id" placeholder="Project Id" />
<input type="text" name="user_id" placeholder="User Id" />
<input type="submit" value="Send Requests" />
{{ Form::close() }}
// Add a new repeating section
$('.addPart').click(function(){
var lastRepeatingGroup = $('.repeatingSection').last();
lastRepeatingGroup.clone().insertAfter(lastRepeatingGroup);
return false;
});
看起來您幾乎已經擁有了。
$('.addPart').click(function(){
$('.repeating').last().clone().insertBefore(this); // inserts before the button
return false;
});
哦,您還需要將.addPart
類添加到HTML中的按鈕。
(如:)
<input type="submit" class="addPart" value="Add Part" />
似乎您正在嘗試使用錯誤的定位符訪問元素:代碼中有.repeatingSection,而html中有.repeating。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.