1

I have the following form. After the search form is submitted and results are returned via an ajax call, I would like the page to jump to an ID - which happens to be the top of the results.

<form class="avail-form">
  ...
   <input type="submit" value="search" />
</form>

<div id="results">Results Found</div>
.
. Results
.

Current attempt that doesn't work.

$(document).ready(function() {
    $('form.avail-form').click(function() {
        $(this).scrollTop($('#results').offset().top);
    });
});

I tried using submit instead of click with no luck. I tried a bunch of different apporaches but can't seem to get it right.

4

1 回答 1

5

只需在请求完成时更改哈希即可。

$.ajax({
    url: ...,
    success: function(){
        window.location.hash = "#results";
    }
});
于 2013-05-02T16:02:17.530 回答