设置焦点(Javascript) [英] set focus (Javascript)

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

问题描述

我正在尝试简单地设置txtUserName的焦点。打开此

登录表单。我输入了一些Javascript,但它不起作用。任何

想法?谢谢!


<%@ Page Language =" vb" AutoEventWireup =" false"
Codebehind =" Login.aspx.vb"

Inherits =" Forsyth.HR_ReportingTool.UI.Login" %>

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">

< HTML>

< HEAD>

< title>登录< / title>

< meta name =" GENERATOR" content =" Microsoft Visual Studio .NET 7.1"

< meta name =" CODE_LANGUAGE" content =" Visual Basic .NET 7.1"

< meta name =" vs_defaultClientScript" content =" JavaScript">

< meta name =" vs_targetSchema" content =" http://schemas.microsoft.com/

intellisense / ie5">

< / HEAD>

< ; body MS_POSITIONING =" GridLayout" bgcolor ="#6699ff"

background =" file:/// C:\Inetpub \ www.root \HR_ReportingTool \ vignette.gif">

< script language =" JavaScript">

函数doFocus(){


if(document.forms [0]。 txtUserName)document.forms [0] .txtUserName.focus();

}

< / script>


< ; form id =" Form1"方法= QUOT;交" runat =" server">

< asp:TextBox id =" txtUserName"

< / asp:TextBox>

< / form>

< / body>

< / HTML>

解决方案

< BLOCKQUOTE> 1。你在哪里实际上叫DoFocus()?

2. asp:TextBox似乎没有正确关闭。


乔治。


" slinky" < ca *************** @ yahoo.com在留言中写道

新闻:a7 *************** ******************* @ e53g2000 hsa.googlegroups.com ...


我正在尝试简单地设置txtUserName的焦点。打开此

登录表单。我输入了一些Javascript,但它不起作用。任何

想法?谢谢!


<%@ Page Language =" vb" AutoEventWireup =" false"
Codebehind =" Login.aspx.vb"

Inherits =" Forsyth.HR_ReportingTool.UI.Login" %>

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">

< HTML>

< HEAD>

< title>登录< / title>

< meta name =" GENERATOR" content =" Microsoft Visual Studio .NET 7.1"

< meta name =" CODE_LANGUAGE" content =" Visual Basic .NET 7.1"

< meta name =" vs_defaultClientScript" content =" JavaScript">

< meta name =" vs_targetSchema" content =" http://schemas.microsoft.com/

intellisense / ie5">

< / HEAD>

< ; body MS_POSITIONING =" GridLayout" bgcolor ="#6699ff"

background =" file:/// C:\Inetpub \ www.root \HR_ReportingTool \ vignette.gif">

< script language =" JavaScript">

函数doFocus(){


if(document.forms [0]。 txtUserName)document.forms [0] .txtUserName.focus();

}

< / script>


< ; form id =" Form1"方法= QUOT;交" runat =" server">

< asp:TextBox id =" txtUserName"

< / asp:TextBox>

< / form>

< / body>

< / HTML>



你不需要JavaScript ......只需加上


txtUserName.focus ();

你的page_load活动中的



Matthew Wells
Ma *********** @ FirstByte.net

" slinky" < ca *************** @ yahoo.com在留言中写道

新闻:a7 *************** ******************* @ e53g2000 hsa.googlegroups.com ...


我正在尝试简单地设置txtUserName的焦点。打开此

登录表单。我输入了一些Javascript,但它不起作用。任何

想法?谢谢!


<%@ Page Language =" vb" AutoEventWireup =" false"
Codebehind =" Login.aspx.vb"

Inherits =" Forsyth.HR_ReportingTool.UI.Login" %>

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">

< HTML>

< HEAD>

< title>登录< / title>

< meta name =" GENERATOR" content =" Microsoft Visual Studio .NET 7.1"

< meta name =" CODE_LANGUAGE" content =" Visual Basic .NET 7.1"

< meta name =" vs_defaultClientScript" content =" JavaScript">

< meta name =" vs_targetSchema" content =" http://schemas.microsoft.com/

intellisense / ie5">

< / HEAD>

< ; body MS_POSITIONING =" GridLayout" bgcolor ="#6699ff"

background =" file:/// C:\Inetpub \ www.root \HR_ReportingTool \ vignette.gif">

< script language =" JavaScript">

函数doFocus(){


if(document.forms [0]。 txtUserName)document.forms [0] .txtUserName.focus();

}

< / script>


< ; form id =" Form1"方法= QUOT;交" runat =" server">

< asp:TextBox id =" txtUserName"

< / asp:TextBox>

< / form>

< / body>

< / HTML>



我用过这个:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

System.EventArgs)处理MyBase.Load

txtUserName.focus()

结束子


但是得到这个:''焦点''不是

''System.Web.UI.webcontrols.TextBox''

$ b $的成员b 6月4日,4:08 * pm,Matthew Wells < Matthew.We ... @ FirstByte.net>

写道:


你不需要JavaScript ......在你的page_load活动中加上


txtUserName.focus();





Matthew Wells

Matthew.We ... @ FirstByte.net


" slinky" < campbellbrian2 ... @ yahoo.com写了留言


新闻:a7 *********************** *********** @ e53g2000 hsa.googlegroups.com ...


我试图简单地设置 txtUserName"打开此

登录表单。我输入了一些Javascript,但它不起作用。任何

想法? * 谢谢!


<%@ Page Language =" vb" AutoEventWireup =" false"
Codebehind =" Login.aspx.vb"

Inherits =" Forsyth.HR_ReportingTool.UI.Login" %>

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">

< HTML>

< HEAD>

< title>登录< / title>

< meta name =" GENERATOR" content =" Microsoft Visual Studio .NET 7.1"

< meta name =" CODE_LANGUAGE" content =" Visual Basic .NET 7.1"

< meta name =" vs_defaultClientScript" content =" JavaScript">

< meta name =" vs_targetSchema" content =" http://schemas.microsoft.com/

intellisense / ie5">

< / HEAD>

< ; body * MS_POSITIONING =" GridLayout" bgcolor ="#6699ff"

background =" file:/// C:\ Inetpub \wwwroot \HR_ReportingTool \ vignette.gif">


< script language =" JavaScript">

function doFocus(){


if(document.forms [0] .txtUserName)document.forms [0] .txtUserName.focus();

}

< / script>


< form id =" Form1"方法= QUOT;交" runat =" server">

< asp:TextBox id =" txtUserName"

< / asp:TextBox>

< / form>

< / body>

< / HTML> - 隐藏引用的文字 -



- 显示引用的文字 -


I''m trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? Thanks!

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">

<script language="JavaScript">
function doFocus(){

if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>

解决方案

1. Where do you actually call the DoFocus()?
2. asp:TextBox seems to be not closed properly.

George.

"slinky" <ca***************@yahoo.comwrote in message
news:a7**********************************@e53g2000 hsa.googlegroups.com...

I''m trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? Thanks!

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">

<script language="JavaScript">
function doFocus(){

if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>



You don''t need JavaScript...Just put

txtUserName.focus();

in your page_load event.

Matthew Wells
Ma***********@FirstByte.net
"slinky" <ca***************@yahoo.comwrote in message
news:a7**********************************@e53g2000 hsa.googlegroups.com...

I''m trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? Thanks!

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">

<script language="JavaScript">
function doFocus(){

if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>



I used this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtUserName.focus()
End Sub

But get this: ''focus'' is not a member of
''System.Web.UI.webcontrols.TextBox''

On Jun 4, 4:08*pm, "Matthew Wells" <Matthew.We...@FirstByte.net>
wrote:

You don''t need JavaScript...Just put

txtUserName.focus();

in your page_load event.

Matthew Wells
Matthew.We...@FirstByte.net

"slinky" <campbellbrian2...@yahoo.comwrote in message

news:a7**********************************@e53g2000 hsa.googlegroups.com...

I''m trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? * Thanks!

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body *MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">

<script language="JavaScript">
function doFocus(){

if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>- Hide quoted text -


- Show quoted text -


这篇关于设置焦点(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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