j查询星级导致页面滚动

jQuery star rating causing page scrolling

本文关键字:滚动 查询      更新时间:2023-09-26

星级中添加按钮后遇到问题。每次我点击星星时,我的页面都会变得跳跃并滚动到顶部。如何防止此行为?

我的代码:

$(document).ready(function(){
        var rate=null;
        $(".one-star, .two-stars, .three-stars, .four-stars, .five-stars").click(function() {
             rate = $(this).html();
             $("#submit_rating").fadeIn("slow");
             $("#current_rating").width(rate*30);
        });
        $('#submit_rating').click(function(){
                $.ajax({data: ({ action: 'save_rating', rating: rate, listing_id: <?php echo $id; ?>}), success: function() { window.location.href = '<?php echo $this->escape(URL); ?>'; }});
                return false;
        });
    });

你可以在这里看到我的问题:http://duniakita.org/starrating/

您可能需要

在单击*-stars时使用e.preventDefault

$(".one-star, .two-stars, .three-stars, .four-stars, .five-stars").click(function(e) {
    rate = $(this).html();
    $("#submit_rating").fadeIn("slow");
    $("#current_rating").width(rate*30);
    e.preventDefault();
});