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");
})
})