0

我不能删除好的评论,它总是删除最后一个。

我的js:

  $(function () {          
        $( ".delete" ).click(function() {
            $( "#delete-confirm" ).dialog( "open" );
        });

        $( "#delete-confirm" ).dialog({
            autoOpen: false, modal: true, width: '600px', show: 'fade',
            buttons: {
                "Confimer": function() {

                    $( this ).dialog( "close" );
                    $('.form-comment').append('<input type="hidden" name="delete" />');
                    $(".form-comment").submit();
                },
                "Annuler": function() {
                    $( this ).dialog( "close" );
                }
            }
        });

    }); 

在 PHP 中:

<?php
 foreach ($commentManager->getList() as $comment) { ?>
     <form class="form-comment" method="post" style="display: inline;">
        <input type="hidden" name="id" value="<?php echo $comment['id']; ?>" />
      </form>
<?php } ?>

我如何提交具有良好 id 的表单而不将我的 jquery 代码放在 php 页面的中间?

4

2 回答 2

0

我认为如果您对此提出 AJAX 请求,最好只获取当前单击的 DOM

并分配attr-table-id给它,然后使用$(this).data('table-id');它并通过 AJAX 发送到您的服务器

如果您不想使用 AJAX ,请进行重定向而不是陷入表单提交问题,因为您正在提交带有该类的所有表单form-comment (Use window.location)

我希望这可以帮助

于 2013-03-08T02:47:39.180 回答
0

我希望我正确理解了您的问题,即您只想删除选定的评论。因此,您可以尝试以下操作:

var goodId = '';
$( ".delete" ).click(function() {
    goodId = $(this).attr('id');
    $( "#delete-confirm" ).dialog( "open" );
});
// and then later make these changes
$('.form-comment-'+goodId).append('<input type="hidden" name="delete" />');
$(".form-comment-"+goodId).submit();
goodId = '';

并在您的 php 代码中:

<?php
 foreach ($commentManager->getList() as $comment) { ?>
     <form class="form-comment-<?php echo $comment['id']; ?>" method="post" style="display: inline;">
        <input type="hidden" id="<?php echo $comment['id']; ?>" name="id" value="<?php echo $comment['id']; ?>" />
     </form>
<?php } ?>

设置 goodId 如果需要,您可以使用 value 属性来获取评论 ID。

于 2013-03-08T02:51:39.840 回答