[英]Issue with javascript repeating div in a form?
I am trying to make a form that only a portion of the form is repeating. 我正在尝试制作一种仅重复表格的一部分的表格。 I was advised on here to use JavaScript for that.
建议我在这里使用JavaScript。 I keep getting an error with my current code.
我的当前代码不断出现错误。 Please help.
请帮忙。
Here is the form: 形式如下:
{{ 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;
});
Looks like you almost had it. 看起来您几乎已经拥有了。
$('.addPart').click(function(){
$('.repeating').last().clone().insertBefore(this); // inserts before the button
return false;
});
Oh, you also need to add the .addPart
class to your button in the HTML. 哦,您还需要将
.addPart
类添加到HTML中的按钮。
(as in:) (如:)
<input type="submit" class="addPart" value="Add Part" />
似乎您正在尝试使用错误的定位符访问元素:代码中有.repeatingSection,而html中有.repeating。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.