将按钮的click事件定位到要点击的div上不就可以达到目的了吗?

解决方案 »

  1.   

    命名锚记   不就可以吗?
    <a href="#a">asd</a><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <a name="a" id="a"></a><div>123</div><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function showSearch(){
    var oDiv=document.getElementById("div6");
    oDiv.scrollIntoView();
    }
    </script>
    </head>
    <body>
    <input type="button" value="Search" onclick="showSearch()"/>
    <div id="div1" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">1</div>
    <div id="div2" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">2</div>
    <div id="div3" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">3</div>
    <div id="div4" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">4</div>
    <div id="div5" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">5</div>
    <div id="div6" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">Search</div>
    <div id="div7" style="width:100px;height:20px;background-color:#999999;margin-top:100px;">7</div><p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
      

  3.   

    6楼的牛,竟然有这个scrollIntoView,不知兼容性通用性如何,一般我们都是用锚#,其它元素还可以用onfocus、select等类似的达到接近效果。
      

  4.   

    记录下你DIV为焦点是滚动条的位置,把按钮的onclick事件加入window.scroll(x,y)(x,y为位置)即可