:input表示选择表单中的input,select,textarea,button元素,input仅仅选择input元素。
<html>
<head>
<style>
.focus{
background-color: blue
}
</style>
</head>
<body>
<script type="text/javascript" src="scripts/jquery.1.6.1.min.js"></script>
<script type="text/javascript">
$(function(){
$(":input").focus(function(){
$(this).addClass("focus");
}).blur(function(){
$(this).removeClass("focus");
});
})
</script>
<form action="" method="post" id="regForm">
<fieldset>
<legend>Personal Info</legend>
<div>
<label for="username">Name:</label>
<input id="username" type="text" />
</div>
<div>
<label for="pass">Password:</label>
<input id="pass" type="password" />
</div>
<div>
<label for="msg">Detail Information:</label>
<textarea id="msg" rows="2" cols="20"></textarea>
</div>
<div>
<select name="single">
<option>Single</option>
<option>Single2</option>
</select>
</div>
<div>
<select name="multiple" multiple="multiple">
<option selected="selected">Multiple</option>
<option>Multiple2</option>
<option selected="selected">Multiple3</option>
</select>
</div>
</fieldset>
</body>
</html>