js两种方式定位div

来源:互联网 发布:windows-X是什么软件 编辑:程序博客网 时间:2024/05/14 09:58
<html><title>js定位div的两种方式</title><head><meta charset="utf-8"><script>    window.onload = function () {        var d = document.getElementById("test");         var nodeList = d.getElementsByTagName("span");         var sing = nodeList[0].innerHTML.replace(/^\s*|\s*$/g, "");        if ( sing != null && sing != "") {            document.body.scrollTop = document.body.scrollHeight;        }     }    //function dingWeiDiv(){    //  window.location.hash = "#test";        //}</script></head><body>    <div>        <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>        <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>    </div>    <div id = "test" >         <span>定位到这里</span>    </div></body></html>
0 0
原创粉丝点击