在FIREFOX中使用Javascript将焦点设置在文本框上 [英] Set Focus on Textbox using Javascript in FIREFOX

查看:99
本文介绍了在FIREFOX中使用Javascript将焦点设置在文本框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议我,如何在Asp.net中使用Javascript将焦点设置在同一文本框中.

Can any one suggest me , How to Set Focus on same Textbox using Javascript in Asp.net.

if(document.getElementById("Textbox1").value=="")
    {
        alert ( ''Invalid Date'' );
        document.getElementById(''Textbox1'').value="";
        document.getElementById(''Textbox1'').focus();
    }



上面的编码是我在Form中使用的"Textbox1"的Javascript. 此编码也可以在INTERNER EXPLORER和GOOGLE CHROME中正常工作,但是如果textbox1为NULL,并且如果我按Textbox1中的Tab按钮,则表示它正在工作(即POPUp消息即将到来),但无法聚焦在相同的Textbox1 本身上当我使用FIREFOX 时.



The Above coding is the Javascript for "Textbox1" which i used in my Form . This coding is working Properly in INTERNER EXPLORER and in GOOGLE CHROME also but if the textbox1 is NULL and if i press Tab button from Textbox1 means its Working(ie., POPUp Message is coming) but its NOT Focusing on the same Textbox1 itself When i use FIREFOX .

推荐答案

在聚焦该字段时增加了一些延迟.像这样的东西:
Add some delay in focusing of the field. Something like this:
<br />
setTimeout(function(){document.getElementById(''Textbox1'').focus()}, 10);<br />



还要确保"document.getElementById"正在返回您所需的元素.

希望这会有所帮助!



Also make sure that "document.getElementById" is returning you the required element.

Hope this helps!


这篇关于在FIREFOX中使用Javascript将焦点设置在文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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