douzhao1912 2014-11-29 23:32
浏览 267

“提交”按钮仅用作锚点的链接

I have the following code:

<form enctype="multipart/form-data" id="search_form" name="search_form" action="thisfile.php#anchorname" method="get">

<!-- Lots of search fields here -->

<input name="search" type="submit" value="Search" />
</form>

<?php if (isset($_GET['search'])) {
// Search in database
?>
<div id="anchorname">
<!-- Table with results here -->
</div>
<?php
}

This works fine in IE (crazy, I know) but in Chrome and Firefox, after the form is submitted and the results table is displayed, the button doesn't resubmit the form but only makes the page scroll down to anchorname. In Chrome I can reload the page by clicking on the address bar and hitting enter, but when I do that in Firefox, nothing happens at all. What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • dongtan9465 2015-05-21 03:31
    关注

    In case this is useful to anyone, here's what I did, using JQuery:

    $(function() {
        // ...
        <?php if (isset($_GET['search'])) { ?>
            var target = $("#anchorname");
            $('html,body').animate({
                scrollTop: target.offset().top
            }, 500);
        <?php } ?>
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包