當前文字框高亮效果程式碼例項

antzone發表於2018-05-25

本章節分享一段程式碼例項,它實現了當前獲取焦點的文字框高亮效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
div {
  width: 242px;
  height: 100px;
  border: 1px solid #171615;
  background-color: #FFC107;
  text-align: center;
  margin: 0 auto;
  line-height: 43px;
}
.add_class {
  border: 2px solid #5A4944;
  background-color: #E8E6D2;
}
</style>
<script>
window.onload = function () {
  var oInput = document.getElementsByTagName('input');
  for (var index = 0; index < oInput.length; index++) {
    oInput[index].onfocus = function () {
      this.className = "add_class";
    };
    oInput[index].onblur = function () {
      this.className = "";
    }
  }
}
</script>
</head>
<body>
<div id="exdiv">
  <label>
    <span>賬號:</span>
    <input type="text">
  </label>
  <label>
    <span>密碼:</span>
    <input type="text">
  </label>
</div>
</body>
</html>

相關文章