小编lan*_*lot的帖子

单击提交按钮时重新加载页面后如何滚动到特定 div?

我正在尝试做一些奇特的事情。我已经成功编写了代码,以便在填写小表单并单击提交按钮时显示数据库中的结果。结果显示在表单的正下方。但我觉得如果页面能自动向下滚动到包含已填写表单结果的 div,那就太好了。我想我必须使用 jquery 或 ajax 来实现这一点。由于我对它们一无所知,因此我在互联网上搜索复制粘贴代码。但它们都不起作用。

单击提交按钮时,页面将重新加载以从数据库中获取结果。我已经获得了当页面从网络重新加载时向下滚动到 div 的代码,但问题是......即使您提交按钮,滚动也会发生没有点击。因此,有人可以给出仅在单击提交按钮时以及重新加载页面后向下滚动到 div 的代码吗?

代码是这样的

<form name="searchdonor" action="" id="form" method="POST" align="center" enctype="application/x-www-form-urlencoded">  
--- ------ ------  
--- ------ ------  
--- ------ ------

</form>  
<input type="submit" name="submit" id="submit" value="Submit"  onclick="return(searchval()); "> 
//the div i want to scroll down is below one 
<div class="col-sm-8" id="what">
</div>  
Run Code Online (Sandbox Code Playgroud)

这是 html 和 php-mysqli 中的完整代码

<div class="col-sm-4">
         <h1 class="register-title">Search a Donor</h1>
              <div id="wrapper">
              <div id="chatbox">
      <form name="searchdonor" action="" id="form" method="POST" align="center" enctype="application/x-www-form-urlencoded">
        <table id="results">
                <tr><td><h4>Country:</h4></td><td>&nbsp&nbsp&nbsp&nbsp&nbsp
                 <select id="slct1" name="country" onchange="populate1(this.id,'slct2')">
                  <option …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax jquery

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

php ×1