JQuery投票问题

发布于 2024-10-15 03:46:53 字数 1393 浏览 10 评论 0原文

我使用此 jQuery 代码在我的网站上投票给新闻作者。

<script type="text/javascript">
    $(function() {
        $(".vote").click(function() 
        {
            var id = $(this).attr("id");
            var name = $(this).attr("name");
            var dataString = 'id='+ id ;
            var parent = $(this);

            if (name=='up')

            {
                $(this).fadeIn(200).html('<img src="dot.gif" />');
                $.ajax({
                    type: "POST",
                    url: "up_vote.php",
                    data: dataString,
                    cache: false,

                    success: function(html)
                    {
                        parent.html(html);
                    } 
                });

            }
            else
            {
                $(this).fadeIn(200).html('<img src="dot.gif" />');
                $.ajax({
                    type: "POST",
                    url: "down_vote.php",
                    data: dataString,
                    cache: false,

                    success: function(html)
                    {
                        parent.html(html);
                    }
                });

            }
            return false;
        });
    });
</script>

这有效!投票后显示感谢或结果的警报框。现在,如果一页中有 9 个帖子(例如 ADMIN 发布)用于投票 9,则显示 9 个警报框!

如何解决这个问题?

I voting to news author in my site with this jQuery code.

<script type="text/javascript">
    $(function() {
        $(".vote").click(function() 
        {
            var id = $(this).attr("id");
            var name = $(this).attr("name");
            var dataString = 'id='+ id ;
            var parent = $(this);

            if (name=='up')

            {
                $(this).fadeIn(200).html('<img src="dot.gif" />');
                $.ajax({
                    type: "POST",
                    url: "up_vote.php",
                    data: dataString,
                    cache: false,

                    success: function(html)
                    {
                        parent.html(html);
                    } 
                });

            }
            else
            {
                $(this).fadeIn(200).html('<img src="dot.gif" />');
                $.ajax({
                    type: "POST",
                    url: "down_vote.php",
                    data: dataString,
                    cache: false,

                    success: function(html)
                    {
                        parent.html(html);
                    }
                });

            }
            return false;
        });
    });
</script>

This worked ! After voting show alert box for thanks or result. Now if in one page 9 posts ( example ADMIN posted ) for voting 9 show 9 alert box !

How to fix this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文