我有这个网址 http://localhost:8080/?london它需要加载到<section id="london">.
中的伦敦ID - 在页面上。
我不能使用 http://localhost:8080/#london ,即使那会起作用!
为了让事情变得更复杂,我正在使用 vue 框架,他们想要 master-origin/src/assets/js/mixins/Anchor.js 中的代码 - 因此我无法安装 jquery,必须是 vanilla js。
我试过了
var el = [];
el = window.location.href.split("/?")[1];
console.log("el: " + el);
el.scrollIntoView();
它在/? 之后获取值,但是当我尝试滚动到 View 时,我在控制台中收到此消息
TypeError: el.scrollIntoView is not a function at VM10022 IE work:4
为什么?我正在关注 w3 学校指南 https://www.w3schools.com/jsref/met_element_scrollintoview.asp
最佳答案
您尝试在字符串上调用 .scrollIntoView()
。
试试这个:document.getElementById(el).scrollIntoView();
关于javascript - 在 url,vue.js 中使用 "?"时滚动到 id 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53352121/