简体   繁体   English

提交按钮仅作为锚点链接

[英]Submit button works only as link to anchor

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. 这在IE中非常有效(我知道这很疯狂),但是在Chrome和Firefox中,提交表单并显示结果表后,该按钮不会重新提交表单,而只会使页面向下滚动到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. 在Chrome浏览器中,我可以通过单击地址栏并按Enter来重新加载页面,但是当我在Firefox中这样做时,什么也没有发生。 What am I doing wrong? 我究竟做错了什么?

In case this is useful to anyone, here's what I did, using JQuery: 如果这对任何人都有用,这就是我使用JQuery所做的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM