0

やあみんなここに投稿データが出てこないので、これがまったく機能していないことはかなり前向きです。重要なのは、ID番号が付加された受け入れ/拒否と、そのフォームのチェックボックスの値を起動することでした。エラーも警告も表示されないので、問題が発生しています=(うまくいけば別の目ですか?

事前に申し訳ありませんが、JQueryが機能しないことを知っています。

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("jquery", "1.6");
    </script>

    <script>
        $(".audit").submit(function() 
            { 
                return false; 
            });

        $(".accept, .deny").click(function(event) 
            {
                $form = $(this).parent("form").get(0);
                $gruden = $form(function(index) { attributes.push($(this).val());});
                $.post($form.attr("action"), $form.serialize() + "&submit=" + $(this).attr("value") + "&gruden=" + $gruden, function(data) {

                console.log(data);

            });
        });
    </script>

.......................

<?php foreach($obj->photos as $pending) { ?>

        <div class='container' id='photo-<?=$pending->id;?>'>

            <span class='shadow'>
            <a href='/<?=$pending->large;?>'><img src='http://<?=$_SERVER['HTTP_HOST'].'/'.$pending->small;?>'/></a>
            </span>

            <form class='audit' name='audit-<?=$pending->id;?>' action='<?=$_SERVER['PHP_SELF'];?>'>
            <div class='box'>

                <ul>

                    <li>ID:   <?=$pending->id;?></li>
                    <li>Date: <?=$pending->created_at;?></li>
                    <li>User: <?=$pending->fb_id;?></li>
                    <li>&nbsp;</li>

                    <li>

                        <input class='gruden' value='gruden-<?=$pending->id;?>' type='checkbox' />
                        <a name='submit' value='accept-<?=$pending->id;?>' class='accept' href=''></a>
                        <a name='submit' value='deny-<?=$pending->id;?>' class='deny' href=''></a>

                    </li>

                </ul>

            </div>
            </form>

        </div>

<?php } ?>
4

2 に答える 2

0

この行は、直接の親のみを参照するため、フォーム要素を確実に返しません。

$form = $(this).parent("form");

次のようなものを試してください。

$form = $(this).parents("form").get(0);
于 2012-07-12T22:00:09.537 に答える
0

私はあなたの問題を今見ていると思います。私はあなたのコードを書き直したので、それはより理にかなっています。何が起こっているのかを説明するコメント

<script>
    $(".audit").submit(function(){ 
            return false; //Preventing the form from submitting if someone hits Enter
    });

    $(".accept, .deny").click(function(event) {
            var form = $("form.audit"); //Always use var to declare variables in Javascript. It's not PHP; we don't use $, unless you want it to be a part of the variable name. Also fixed your selector
            var gruden = $form(function(index) { attributes.push($(this).val());}); //Are you trying to find out if the checkbox with class gruden is checked? Please answer in the comments so I can correct this line
            $.post(form.attr("action") + "&submit=" + $(this).attr("value") + "&gruden=" + gruden, form.serialize(), function(data) { 
                   console.log(data);
            }); //I assume that you want to pass submit and gruden as GET params here, since you're appending them to the URL. If you want them to go as POST vars, then let me know in the comments
    });
</script>

不快感はありませんが、JavascriptとjQueryについてもう少し読むことでメリットが得られると思います。少なくとも、jQueryでセレクターがどのように機能するか、およびいくつかの基本的なJavascript構文について読んでください。

于 2012-07-12T22:08:05.900 に答える