当页面通过Ajax加载时,将焦点放在文本框中 [英] Focus in Textbox when the page is Loaded through Ajax

查看:51
本文介绍了当页面通过Ajax加载时,将焦点放在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这是ram。


我正在开发一个带有两个文本框的页面(usereg.jsp),一个用于用户名和另一个电子邮件。由于我使用Ajax在main.jsp中使用此页面,因此我将删除usereg.jsp中的正文部分。


现在我需要将光标聚焦在usereg.jsp的第一个文本框中。由于这个jsp中没有body标签,我无法调用onload =" document.formname.textboxname.focus()"。


但是当我打电话时我需要在文本框中关注焦点这个页面在main.jsp中。


即使我试图通过在这个页面中编写单独的java脚本来将texbox集中在usereg.jsp中。当我执行这个页面(usereg.jsp)时,聚焦文本框的问题就解决了。


但是当我在main.jsp中调用这个页面时,我写的是java脚本,焦点没有反映。


请建议我哪里出错了..


我的邮件是:****

Hi,

This is ram.

I am developing a page(usereg.jsp) with two textboxes one for username and another for email. Since i am using this page in main.jsp using Ajax, I am removing the body part in usereg.jsp.

Now i need to focus the cursor in first textbox of usereg.jsp. Since there is no body tag in this jsp i cannot call onload="document.formname.textboxname.focus()".

But i need the focus in textbox when i call this page in main.jsp.

Even i have tried to focus the texbox in usereg.jsp by writing the seperate java script in this page. When i execute just this page(usereg.jsp) the problem of focusing text box is solved,,

But when i call this page in main.jsp along with the java script i wrote, the focus is not reflecting.

Please suggest me where am i going wrong..

my mailid is: ****

推荐答案

如果您使用的是Ajax,请使用onreadystatechange事件处理程序。一旦值为4,你可以调用一个处理响应的函数,所以在该函数中包含焦点代码。
If you are using Ajax, use the onreadystatechange event handler. Once the value is 4, you can call a function which deals with the response so include the focus code in that function.


我遇到了同样的问题,但试着把焦点放在功能,它仍然无法正常工作。这是我的javascript
I''m having the same problem but tried doing the focus in the function and it still doesn''t work. Here''s my javascript:
展开 | 选择 | Wrap | 行号



这是调用焦点的错误位置,还是我的调用语法错误?
Is this the wrong place to call for focus, or do I have the call syntax wrong?



AJAX中的第一个'A'代表''异步''。换句话说,在您的AJAX请求返回之前,handleHttpResponse不会被执行。 然而,您的脚本将继续评估代码,直到请求返回。


所以当你把dono.focus()放在doStuff中时:

The first ''A'' in AJAX stands for ''Asynchronous''. In other words, handleHttpResponse won''t get executed until your AJAX request returns. However, your script will continue to evaluate code until the request returns.

So when you put recno.focus() inside of doStuff:

展开 | 选择 | Wrap | 行号


这篇关于当页面通过Ajax加载时,将焦点放在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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