HTML DOM focus()和blur()方法 輸入框滑鼠指過自動消失滑鼠離開顯示 js

來源:互聯網
上載者:User
文章目錄
  • 文法
定義和用法

focus() 方法用於在密碼域上設定焦點。

文法
passwordObject.focus()
執行個體

下面的例子可設定或移開密碼域上的焦點:

<html><head><script type="text/javascript">function setFocus()  {  document.getElementById('password1').focus()  }function loseFocus()  {  document.getElementById('password1').blur()  }</script></head><body><form><input type="password" id="password1" value="thgrt456" /><input type="button" onclick="setFocus()" value="Set focus" /><input type="button" onclick="loseFocus()" value="Lose focus" /></form></body></html>

執行個體2:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>

<script type="text/javascript">
       function chg(){
       document.getElementById("setfocus").value="";
       }
       function newChg(){
       document.getElementById("setfocus").value="請輸入關鍵字";
       }
</script>

</head>

<body>
<input type="text" name="name" size="15" class="input" id="setfocus" value="請輸入關鍵字" onfocus="chg()" onblur="newChg()">

</body>
</html>

執行個體3

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>

<script type="text/javascript">
function $(ID) {return document.getElementById(ID);}
function chg(){
$("setfocus").value="";
}
function newChg(){
    if($("setfocus").value==""){
        $("setfocus").value="請輸入關鍵字";
        }
    else{return $("setfocus").value }
}
</script>

</head>

<body>
<input type="text" name="name" size="15" class="input" id="setfocus" value="請輸入關鍵字" onfocus="chg()" onblur="newChg()">

</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.