js獲得焦點和失去焦點那些事

來源:互聯網
上載者:User

標籤:

<!doctype html><html><head><meta charset="utf-8"><meta name="author" content="智能社 - zhinengshe.com"><meta name="copyright" content="智能社 - zhinengshe.com"><title>智能社 - www.zhinengshe.com</title><style>* { margin:0; padding:0; }.box {position:relative; width:200px; margin:50px auto;}.box span { position:absolute; top:0; left:5px; height:40px; line-height:40px; color:#999; }#inp1,#pass{ position:absolute; top:0; left:0; border:1px solid #000; /* border:none 0;這個是相容的寫法 */outline:none;width:190px; height:40px; line-height:40px; padding:0 5px; background:none;}#pass{top:55px;}input::-ms-clear { display:none; } /* 去掉IE10輸入框後的叉號 */input::-ms-reveal{ display:none;}    /* 去掉輸入密碼時的眼睛 */</style><script>window.onload=function (){    var oInp=document.getElementById(‘inp1‘);    var oSpan=document.getElementById(‘span1‘);        oInp.onfocus=function (){        oSpan.style.display=‘none‘;    };    oInp.onblur=function (){//失去焦點判斷輸入為空白時                if (oInp.value.length == 0)        {            oSpan.style.display=‘block‘;        }        };    oSpan.onclick=function (){//點擊提示文字時情況        oInp.focus();    };};</script></head><body>    <div class="box">        <input type="text" id="inp1" />        <span id="span1">我是提示文字</span>        <input type="password" id="pass"/>     </div>   </body></html>

 

js獲得焦點和失去焦點那些事

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.