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

我想我现在看到了你的问题。我已经重写了你的代码,所以它更有意义。评论来解释发生了什么

<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 回答
0

此行肯定不会返回您的表单元素,因为它只查看直接父级。

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

尝试这样的事情:

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