input獲取焦點失去焦點變化
阿新 • • 發佈:2019-01-04
input獲取失去焦點
實現功能:input在獲取焦點後新增邊框,失去焦點後恢復原樣。
.focus {
border: 1px solid blue;
}
<form action="#" method="POST" id="regForm">
<fieldset>
<legend>個人基本資訊</legend>
<div>
<label for="username">名稱:</label>
< input id="username" type="text">
</div>
<div>
<label for="pass">密碼:</label>
<input id="pass" type="password">
</div>
<div>
<label for="msg">詳細資訊:</label>
<textarea id ="msg"></textarea>
</div>
</fieldset>
</form>
$(function() {
$(":input").focus(function() {
$(this).addClass("focus")
}).blur(function() {
$(this).removeClass("focus");
})
})