使用Javascript将焦点设置在文本框上 [英] Set Focus on Textbox using Javascript
问题描述
任何人都可以建议我,如何在Asp.net中使用Javascript设置对文本框的关注当我按下TAB按钮时。
Can any one suggest me , How to Set Focus on Textbox using Javascript in Asp.net When i press TAB button .
if(document.getElementById("Textbox1").value=="")
{
alert ( 'Invalid Date' );
document.getElementById('Textbox1').value='__/__/____';
document.getElementById('Textbox1').focus();
}
以上编码是我在表格中使用的Javascript。这个编码正常工作但是如果textbox1为NULL并且我按下Textbox1中的Tab按钮意味着它的工作(即,POPUp消息即将到来)但它没有关注Textbox1本身。
先谢谢。
问候,
SARAVANAN.M
The Above coding is the Javascript which i used in my Form . This coding is working Properly 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 Textbox1 itself .
Thanks in Advance.
Regards,
SARAVANAN.M
推荐答案
这里的第一个错误是在第一行,必须是:
First bug here is in the first line, must be:
var textBox = document.getElementById("Textbox1");
if (textBox)
/*...*/
>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Textbox1" runat="server"></asp:TextBox>
</div>
<script language="javascript" type="text/javascript">
if (document.getElementById("Textbox1").value == "") {
alert("Invalid date");
document.getElementById('Textbox1').value = '__/__/____';
document.getElementById("Textbox1").focus();
}
</script>
</form>
它适用于我。
It is working properly for me.
使用此代码
use this code
<script language="javascript" type="text/javascript">
if (document.getElementById("Textbox1").value == "") {
alert("Invalid date");
document.getElementById('Textbox1').value = '__/__/____';
document.getElementById("Textbox1").focus();
}
我的工作正常。
It is working fine for me.
这篇关于使用Javascript将焦点设置在文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!