如何在ASP.NET中使用JS将滚动条的位置放在必填字段在sumbit上的位置? [英] How do I make the scrolls position where the required field is on sumbit with JS in ASP.NET ?

查看:48
本文介绍了如何在ASP.NET中使用JS将滚动条的位置放在必填字段在sumbit上的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我被困在以下问题上:


我有一张注册表,上面有名字,姓氏,电子邮件.页面底部有一个提交按钮.如果用户输入页面顶部的字段,其余部分留空,我希望页面滚动到所需字段所在的位置.现在,页面自动转到页面顶部.

感谢您的宝贵时间.

Hello,

I am stuck on the following issue:


I have a registration form with first name, last name, email as a table. At the bottom of the page there is a submit button. If the user enters fields that are on top of the page and leaves blank the rest, I would like the page to scroll to the position where the required field is. Right now the page goes automatically to the top of the page.

Thanks for the time.

推荐答案

我认为这不是完成您所要求的方法的好方法,但是根据控件的不同,您可以指定"y轴"通过将其传递给下面的javascript函数来手动设置值.
I think this is not a good way to accomplish what you ask for but depending on the control you can give the "y-axis" value manually by passing it to the javascript function below.
<script type="text/javascript" language="javascript">
       function pageScroll(int y) {
           window.scrollBy(0, y); // horizontal and vertical scroll increments
                   }
   </script>



祝你好运.



Good luck..


出于良好的原因,您无法控制客户端的滚动.
我能看到的唯一方法是在每个字段上放置一个锚点,并将字段的锚点名称传递到第一个字段(按从上到下的顺序),以照看URL.
例如,如果您页面的URL为http://www.domain.tld/directrory/resource.html,而您的锚定字段为<a name="email" />,则使用URL http://www.domain.tld/directrory/resource.html#email导航至此电子邮件"字段.



要确定在表单上每个控件中输入的内容,您需要检查所有这些控件的值;使用类似这样的内容:document.GetElementById("myControlId").value.

此外,您可以在事件驱动下进行此检查,并在每次控件中的数据发生更改时执行一些计算,但不要立即进行导航,请等到尝试发送所有数据为止.像这样的东西:

You do not control scrolling by the client, for a good reason.
The only approach I can see is putting an anchor to each field and pass the anchor name of a field to first (in top-to-down order) field to be attended to the URL.

For example, if your page''s URL is http://www.domain.tld/directrory/resource.html and your anchor before the field is <a name="email" />, use URL http://www.domain.tld/directrory/resource.html#email to navigate to this "e-mail" field.



To identify what is entered in each control on the form you need to check the values of all those controls; use something like this: document.GetElementById("myControlId").value.

Additionally, you can make this check driven by events and perform some calculations each time a data in control has changes, but don''t navigate immediately, wait until all data is attempted to send. Something like this:

<input type="text" onChange="findFirstNonEditedElement()">



—SA



—SA


这篇关于如何在ASP.NET中使用JS将滚动条的位置放在必填字段在sumbit上的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆