js實現input密碼框提示資訊的方法(附html5實現方法),inputhtml5

來源:互聯網
上載者:User

js實現input密碼框提示資訊的方法(附html5實現方法),inputhtml5

本文執行個體講述了js實現input密碼框提示資訊的方法。分享給大家供大家參考,具體如下:

今天我們主管說要在密碼框加入個"請輸入密碼"的提示資訊,第一次的時候本來想著用修改input  type 屬性的方法呢,結果有某些特別的瀏覽器不支援,IE的input的type屬性是唯讀,不能動態設定.所以換其它的方法,執行個體如下:

<input type="text" onfocus="changeTip(this);" id="passText" name="passText" value="請輸入密碼"/><input style="display: none;" type="password" onblur="changeTip(this);" id="pass" placeholder="" name="pass" value=""/><script type="text/javascript">function changeTip(th){  var passText = document.getElementById('passText');  var pass = document.getElementById('pass');  if(th.id == 'pass'){    if(th.value == '' || th.value.length == 0 ){      passText.style.display='';      pass.style.display='none';    }  }else{    passText.style.display='none';    pass.style.display='';    pass.focus();  }}</script>

補充:

其實上面一大段的代碼,用html5的一個 placeholder 屬性就解決了.代碼如下:
複製代碼 代碼如下:<input type="password" id="pass5" placeholder="請輸入密碼" name="pass5" value=""/>

希望本文所述對大家JavaScript程式設計有所協助。

您可能感興趣的文章:
  • jQuery簡單實現input文字框內灰色提示文字效果的方法
  • input輸入框滑鼠焦點提示資訊
  • 控制input輸入框中提示資訊的顯示和隱藏的方法
  • 讓input框實作類別似百度的搜尋提示(基於jquery事件監聽)
  • 基於jQuery的input輸入框下拉提示層(自動郵箱尾碼名)
  • inputSuggest文字框輸入時提示、自動完成效果(郵箱輸入自動補全外掛程式)
  • jQuery實現表單input中提示文字value隨滑鼠焦點移進移出而顯示或隱藏的代碼
  • js操作輸入框提示資訊且響應滑鼠事件
  • 讓超連結顯示提示資訊的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.