js两种方式定位div

<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>

猜你喜欢

转载自blog.csdn.net/qq_27464169/article/details/51068873
今日推荐