我查看了堆栈上的一些类似帖子,但找不到答案或解决方案。追加发生后,我提交表单并且 var 为空。我检查了 html,在附加输入字段后,它看起来不错:
<input type="hidden" name="imgdelete[]" value="5">
请帮忙,花了3个多小时。谢谢
查询
$('a.delete-img').bind('click',function()
{
var imgid = $(this).attr('id');
// add hidden field to let php know that this image was deleted
$('<input>').attr({
type: 'hidden',
name: 'imgdelete[]',
id: imgid,
value: imgid
}).prependTo('.tablepics tr:last');
});
HTML
<html>
<head></head>
<body>
<form action="" method="post" id="editCarForm" novalidate="novalidate" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="0" class="tablepics" id="id-form">
{foreach from=$CARIMGS item=carimg}
<tr class="car-row">
<td id="{$carimg.imgid}">
<a class="fancybox" href="../{$carimg.img}">
<img width="{$THUMB_WIDTH}" alt="" src="../{$carimg.thumb}"/></img>
</a>
</td>
<td style="padding:5px" id="{$carimg.imgid}">
<input type="text" id="imgorder" name="imgorder[{$carimg.imgid}]" value="{$carimg.order}" size="2" maxlength="2" />
<br><br>
<a href="javascript:void(0);" id="{$carimg.imgid}" class="delete-img">delete</a><br>
</td>
</tr>
{/foreach}
<tr>
<br>
</tr>
<tr>
<th>Images: </th>
<td><input name="upload[]" type="file" accept="image/*" multiple="multiple" /></td>
</tr>
<tr>
<th> </th>
<td valign="top"> //this would be last one
<input type="submit" value="" class="form-submit" />
<input type="reset" value="" class="form-reset" />
</td>
</tr>
</table>
</form>
</body>
</html>