在JSP上的Struts项目中自动滚动 [英] Auto Scrolling in struts project on jsp

查看:51
本文介绍了在JSP上的Struts项目中自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将struts框架与jquery一起使用,并且有按钮.单击该按钮时,如果数据有效,则会调用保存数据的动作,否则将在top div中显示错误.但是问题是它没有滚动显示用户错误,我希望它滚动显示用户错误消息.

i am using struts framework along with jquery and there is button. On click of that button action to save data is called if data is valid else error in top div is shown. But the problem is that its not scrolling to show user error and i want it to scroll to show user the error message.

我知道可以使用href ='#'来解决它,但是它已经被用于调用操作.

I know that it can be solved using href='#' but it is already being used to call the action.

推荐答案

您的问题并没有真正弄清楚此验证是在客户端进行还是在说从服务器响应,而您还没有没有显示任何代码,所以我不确定您到底需要在哪里放置以下内容以适合您现有的实现,但是无论如何,您都可以像这样将元素引入视图:

Your question doesn't really make it clear whether this validation happens client-side or if you're talking 'bout a response from the server, and you haven't shown any code, so I'm not sure where exactly you need to put the following to fit your existing implementation, but anyway you can bring an element into view like this:

document.getElementById("idofyourdivhere").scrollIntoView(true);

参数true应该使元素与滚动区域的顶部对齐;如果您通过false,则应该与底部对齐.

The parameter true should align the element to the top of the scrolling area; if you pass false instead it should align with the bottom.

我不知道是否有一个jQuery方法可以执行相同的操作,但是您当然可以使用jQuery选择div(您可能已经这样做来设置错误消息),然后调用non-jQuery函数-以下内容使用jQuery设置错误消息并取消隐藏div(显然,这是假定它最初是隐藏的),然后才将其以非jQuery的方式显示在视图中:

I don't know if there's a jQuery method to do the same thing, but of course you can select the div with jQuery (you might already be doing so to set the error message) and then call the non-jQuery function - the following uses jQuery to set the error message and unhide the div (obviously this assumes it was hidden initially) before bringing it into view the non-jQuery way:

var yourDiv = $("#idofyourdivhere");
yourDiv.html("Your error message here").show();

yourDiv[0].scrollIntoView(true);

这篇关于在JSP上的Struts项目中自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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