input获取焦点失去焦点变化

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

猜你喜欢

转载自blog.csdn.net/zsm4623/article/details/84589416