为什么返回顶部按钮,按第一次起作用回到了顶部,按第二次却不起作用了?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <title>b</title> <style type= "text/css" > .box1{height: 1400px;background: #ccc;} .box2{height: 1400px;background: #666;} </style> </head> <body> <div class= "box1" id= "top" ></div> <div class= "box2" ></div> <input type= "button" name= "btn" value= "返回顶部" > <script type= "text/javascript" > // console.log(location.href); // console.log(location.hash); var btn=document.getElementsByTagName( 'input' )[0]; btn.onclick= function (){ location.hash= '#top' ; } </script> </body> </html> |
0
收起
正在回答 回答被采纳积分+1
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧