gpt4 book ai didi

javascript - 以html形式一次删除两个动态字段

转载 作者:行者123 更新时间:2023-12-02 20:54:38 25 4
gpt4 key购买 nike

一次添加两个输入字段效果很好,但如何根据需要删除两个输入字段。

引用:https://phppot.com/php/php-contact-form-with-custom-fields/

示例代码

<div id="custom-box">
<label class="custom-input-label">Custom Fields</label>
<div id="custom-input-container">
<div class="input-row">
<input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" name="custom_name[]" />
<input style="width:49%!important; float:right;" type="number" placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" name="custom_value[]" />
</div>
</div>
<input type="button" class="btn-add-more" value="Add More" onClick="addMore()" />
</div>

和 Java 脚本来添加更多字段

function addMore() {
$("<DIV>").load("input.php", function() {
$("#custom-input-container").append($(this).html());
});
}

input.php页面内容

<div class="input-row">
<input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" name="custom_name[]" />
<input style="width:49%!important; float:right;" type="number" placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" name="custom_value[]" />
</div>

最佳答案

我正在删除类名“input-row”的最后一个选择器,它确实有效。解决办法如下:

Javascript:

function deleteMore() {
$("<DIV>").load("input.php", function() {
$(".input-row:last").remove();
});
}

HTML

<input type="button" class="btn-add-more" value="Delete More" onClick="deleteMore()" 
/>

关于javascript - 以html形式一次删除两个动态字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61517624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com