Javascript method to realize clicking back to the top of the page

1: Define the method.

<script>
        // 点击按钮,返回顶部
        function toTop() {
            document.body.scrollTop = 0;
            document.documentElement.scrollTop = 0;
        }
</script>

2: How to use, take button as an example.

<button onclick="toTop()">返回顶部</button>

3: OK.

Guess you like

Origin blog.csdn.net/m0_59778008/article/details/126817489