0

我在iframe中有以下jQuery代码:

<script>
jQuery("#logBtn").click(function(){
    jQuery("#content-promo").load("/path/to/file.php", function(response, status, xhr) {
      if (status == "error") {
      var msg = "Sorry but there was an error: ";
      $("#error").html(msg + xhr.status + " " + xhr.statusText);
      }else{ //update
        $("html, body").animate({ scrollTop: 0 }, "slow");
      }
    });

    return false;
});
</script>

在 AJAX 请求之后,iframe 如何滚动回顶部?

4

3 回答 3

1

我找到了解决方案。我已经添加了下面的代码file.php,它现在可以工作了。

<script> window.parent.parent.scrollTo( 0, 800 ); </script>

于 2013-06-19T12:02:39.553 回答
0

利用:

$('#my-frame').scrollTop();
于 2013-06-19T11:28:08.987 回答
0

您可以使用此代码window.scrollTo(x-coord, y-coord);

在哪里

Parameters    
    * x-coord is the pixel along the horizontal axis.
    * y-coord is the pixel along the vertical axis.
于 2013-06-19T11:28:47.733 回答