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;
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号