2013-08-29 35 views
0

我已经看过一些类似的帖子,但找不到答案或解决方案。追加发生后,我提交表单和var出来是空的。我检查了html,在追加输入字段后,它看起来不错:

<input type="hidden" name="imgdelete[]" value="5"> 

请帮忙,花了3个多小时。谢谢

JQUERY

$('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>&nbsp;</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> 
+2

是你的'

'元素? – Sergio

+0

我没有看到''......如何提交任何内容? –

+0

尝试更改'name:'imgdelete []','只是'name:'imgdelete','因为您的表单已经包含'[]' –

回答

1

试试这个:

$('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('#editCarForm'); 
}); 

这就将隐藏字段到表外的形式。您的代码创建了无效的DOM,因为您有<input>元素作为<tr>的直接子元素,这是不允许的。

+0

工作,谢谢。没有意识到DOM会刹车。学到了新东西。 – Tatarin