mysearchblog

匹配当前获取焦点的元素。

  如同其他伪类选择器(那些以":"开始),建议: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>

 

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案