weixin_33708432 2015-07-18 12:41 采纳率: 0%
浏览 53

AJAX导致跳转到顶部

I do know this is a duplicate but I've tried placing e.preventDefault, and it still jumps.

$(".a-result").click(function(e) {
    <some code....>

    $.post(result + "/fineart/show", {id: $artwork_id})
        .done(function(data){
            $rowBeginner.before(data);
    });

});

Any help on how to stop AJAX from causing a jump to the top would be greatly appreciated.

.a-result is a collection of divs by the way.

Edit

<div id="results-panel">
    <% @artwork_q.each.with_index do |art, index| %>
        <div class="a-result" id="<%= index %>">
            <div class="a-result-photo">
                <%= image_tag art.photo.url(:small) %>
            </div>
            <div class="a-result-info">
                <%= art.artist.last_first if art.artist.present? %><br>
                <strong><%= art.title %></strong><span class="hidden_id"><%= art.id %></span><br>
            </div>
        </div>
    <% end %>
</div>

In the #results-panel, I'm cycling through a rails collection of results, and then place an AJAX div in between one of them.

Also, I am using jquery's offset() and offset().top functions if that would have anything to do with it. I'm using the offset() function to test whether the each successive div is offset from the top the same amount, therefore telling me if they're on the same row, since I'm floating all of them. If this is causing it, might there be a better way to achieve this?

  • 写回答

2条回答 默认 最新

  • 狐狸.fox 2015-07-18 12:57
    关注
    $(".a-result").click(function(e) {
        <do whatever you want....>
        return false;
    });
    
    评论

报告相同问题?