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 } ?>

phpページの中央にjqueryコードを配置せずに、適切なIDでフォームを送信するにはどうすればよいですか?

4

2 に答える 2

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 に答える