【发布时间】:2018-04-26 14:06:46
【问题描述】:
我一直在尝试在页面加载时自动转到网页底部。在get AND post上,其实无论view怎么调用,都要自动到页面底部。
我想用 javascript 来做。
看起来很简单,我可以在这里轻松找到。好吧,看起来像这样:
Set page scroll position on page load of MVC app
只有一个问题...答案没有将 javascript 解决方案置于上下文中。而且没有上下文...我不知道将这些行放在哪里,无论我尝试什么...
我不会玩一整天才知道如何做到这一点,所以这里有一个上下文:
@model WhateverModelYouWant
@{
ViewBag.Title = "Formulaire de reprise";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
document.getElementById("ImportantStuff").scrollIntoView();
</script>
<h2> TITLE OF THE VIEW <h2>
<div> Lots of content here </div>
<div> Even more content here </div>
<div id="ImportantStuff"> Important stuff here </div>
<input type="submit" value="ImportantButton" >
不用说这不会使页面滚动到任何地方...提前致谢。
错误:
【问题讨论】:
标签: javascript html asp.net-mvc