1 回答

TA貢獻1772條經驗 獲得超5個贊
如果您想存儲在數據庫中,我假設您在填寫結束時提交此表格。
然后您應該將索引添加到各個行。您將在 variable 下獲得數組$_POST['pname']。
$(document).ready(function(){
let id_no = 0;
$(".packs").on('click', '.add-icon', function () {
id_no += 1;
$(".packs").append('<div><input type="text" placeholder="Enter Name" name="pname[' + id_no + ']" class="pname" value="Test" /><img class="add-icon" src="media/icon/add.png" height="30" width="30"></div>');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="packs">
<div>
<input type="text" placeholder="Enter Name" name="pname[0]" id="pname" value="Test" />
<img class="add-icon" src="media/icon/add.png" height="30" width="30">
</div>
</div>
- 1 回答
- 0 關注
- 188 瀏覽
添加回答
舉報