[ jquery选择器 :focus ] 此选择器匹配当前获取焦点的元素
匹配当前获取焦点的元素。
如同其他伪类选择器(那些以":"开始),建议:focus前面用标记名称或其他选择;否则,通用选择("*")是不言而喻的。换句话说,$(':focus')等同为$('*:focus')。如果你正在寻找当前的焦点元素,$( document.activeElement )将检索,而不必搜索整个DOM树。
实例:
<!DOCTYPE html>
<html lang='zh-cn'>
<head>
<title>Insert you title</title>
<meta http-equiv='description' content='this is my page'>
<meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type='text/javascript' src='./js/jquery-3.0.0.js'></script>
<style type='text/css'>
input{padding-left:8px;font:400 13px/1.2em 'Courier New';}
.focused{background:#E9B;color:#000;outline:none;}
</style>
<script type='text/javascript'>
$(function(){
$("input:focus").addClass('focused');
});
</script>
</head>
<body>
<form id='formDemo'>
<input type='text' value='user' autofocus='on'/>
<input type='password' value='password' autofocus='off'/>
</form>
</body>
</html>