1、伪类:focus
<!DOCTYPE html>
<html>
<head>
<title>Char 5</title>
<meta charset="utf-8"/>
<style type="text/css">
input:focus{
border-color: red;
}
/*.focus{
border-color: red;
}*/
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// $(function(){
// $(":input").focus(function() {
// $(this).addClass('focus');
// }).blur(function(event) {
// $(this).removeClass('focus');
// });
// })
</script>
</head>
<body>
<div class="person">
<p>姓名:<input type="text" name="name"></p>
<p>密码:<input type="password" name="password"></p>
<p>详细信息:<input type="textarea" name="textarea"></p>
</div>
</body>
</html>
2、ie6只支持:hover.使用jq实现相同效果
<!DOCTYPE html>
<html>
<head>
<title>Char 5</title>
<meta charset="utf-8"/>
<style type="text/css">
.focus{
border-color: red;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$(":input").focus(function() {
$(this).addClass('focus');
}).blur(function(event) {
$(this).removeClass('focus');
});
})
</script>
</head>
<body>
<div class="person">
<p>姓名:<input type="text" name="name"></p>
<p>密码:<input type="password" name="password"></p>
<p>详细信息:<input type="textarea" name="textarea"></p>
</div>
</body>
</html>