我想实现得到焦点时文本框一个样式,失去焦点时文本框一个样式,但现在是只有在得到焦点时样式有变化,失去焦点时样式没有任何变化。刚学jquery,望指教。jQuery.fn.extend({
_focus:function(){
return this.each(this.focus(function(){this.className="FormFocus";}));
},
_blur:function(){
return this.each(this.blur(function(){this.className="FormBase";}));
}
});
$(document).ready(function(){
$("input[@type='text'],input[@type='password'],textarea")._focus();
$("input[@type='text'],input[@type='password'],textarea")._blur();
});
解答
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function(){
$("input:text,input:password,textarea").focus(function(){$(this).css("background","#CBFE9F");}).blur(function(){$(this).css("background","#FFF");});
});
</script>
</head>
<body>
<input type="text" />
<br />
<input type="password" />
<br />
<textarea></textarea>
</body>
</html>
运行后刷新一次