jQuery学习笔记(5)--表单域获得焦点和失去焦点样式变化

时间:2023-12-21 08:29:08
 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<style type="text/css"> <%-- IE6不支持这种方法--%>
<%--input:focus, textarea:focus
{
border: 1px solid #f00;
background:#fcc;
}--%> .focus
{
border: 1px solid gray;
background:gray;
} </style>
<script type="text/javascript"> $(function () {
$(":input").focus(function () {
$(this).addClass("focus");
}).blur(function () {
$(this).removeClass("focus");
}); }); </script>
</head>
<body>
<form id="form1" runat="server" method="post">
<div style="width: 300px; border: 1px solid black">
<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" rows="5" cols="10"></textarea>
</div>
</fieldset>
</div>
</form>
</body>
</html>

效果图:

jQuery学习笔记(5)--表单域获得焦点和失去焦点样式变化