网页SetFocus()和Focus()设置登陆控件焦点|tab顺序设置

早上遇到问题,要设置登陆文本框焦点。也就是说进入登陆页面,光标闪烁输入状态!
设置方法 很多:罗列几种!
方法1
<html>  
<body>  
<input id="username" style="FONT-SIZE: 9pt; WIDTH: 120px; COLOR: black" maxlength="18" value="hello" name="username" />
  <input   type=text   id=text2   value="hello2">   
  <script   language=javascript>  
  username.focus();  
  </script>  

</body>  
  </html>

<HTML>
<HEAD>
<TITLE> 登录页面 </TITLE>

方法2
<script language="javascript" event="onkeydown" for="document"> 
<!–
if(event.keyCode==13) 

  document.all(‘TBUTTON’).click(); 
}
–>
</script> 
</HEAD>
<BODY ONLOAD="window.document.forms[0].username.focus();">
<FORM ACTION="" NAME="TEST" METHOD="POST">
用户名:<INPUT TYPE="TEXT" NAME="username" tabindex="1"><BR>
密码:
<INPUT TYPE="TEXT" NAME="PASSWORD" tabindex="2"><BR>
<INPUT TYPE="BUTTON" NAME="TBUTTON" VALUE="回车" onclick="alert(‘已经点击!!’);" tabindex="3">
</FORM>
</BODY>
</HTML>
 至于TAB顺序设置,很简单,在控件上属性里加上TABINDEX="1" 序号标示先后
<input TABINDEX="1" id="username" style="FONT-SIZE: 9pt; WIDTH: 120px; COLOR: black" maxlength="18"  name="username" />
以上是存档,高手勿看,免得我以后又忘了怎么设置focus,省得去百度!
版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《网页SetFocus()和Focus()设置登陆控件焦点|tab顺序设置

随机文章

{ Leave a Reply ? }

  1. kangzj China Internet Explorer Windows

    学习了,tab那个一直不知道怎么弄来着,谢谢~~

  2. 汤博客 China 360 Browser Windows

    博客文章不错。今天到访,望回访。:》

  3. 就点 China Internet Explorer Windows

    不错 收下了 谢博主

  4. 37xiao China Internet Explorer Windows

    不错!学习……

  5. cgc China Internet Explorer Windows

    背景图挺好看的

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)