jQuery ( ": focus")

· 8년 전 · 1785

jQuery ( ": focus")


설명 : 현재 포커스가있는 경우 요소를 선택합니다.

다른 의사 클래스 선택기 ( ":"로 시작하는 선택기) :focus와 마찬가지로 태그 이름이나 다른 선택기를 사용하는 것이 좋습니다 . 그렇지 않으면 범용 선택기 ( "*")가 내포됩니다. 다른 말로하면, 벌거숭이 $( ":focus" )는에 해당합니다 $( "*:focus" ). 현재 포커스 된 요소 $( document.activeElement )를 찾고있는 경우 전체 DOM 트리를 검색하지 않고도 검색합니다.


예:

포커스가있는 요소에 초점을 맞춘 클래스를 추가합니다.


<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>focus demo</title>

  <style>

  .focused {

    background: #abcdef;

  }

  </style>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

 

<div id="content">

  <input tabIndex="1">

  <input tabIndex="2">

  <select tabIndex="3">

    <option>select menu</option>

  </select>

  <div tabIndex="4">

    a div

  </div>

</div>

 

<script>

$( "#content" ).delegate( "*", "focus blur", function() {

  var elem = $( this );

  setTimeout(function() {

    elem.toggleClass( "focused", elem.is( ":focus" ) );

  }, 0 );

});

</script>

 

</body>

</html>

|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
jQuery
[jQuery]
8년 전 조회 1,859
jQuery 8년 전 조회 5,448
기타 8년 전 조회 3,185
jQuery
[jQuery]
8년 전 조회 1,562
jQuery 8년 전 조회 1,737
jQuery 8년 전 조회 1,836
PHP 8년 전 조회 5,161
node.js 8년 전 조회 4,163
jQuery 8년 전 조회 2,235
jQuery 8년 전 조회 1,677
jQuery 8년 전 조회 1,228
jQuery 8년 전 조회 1,950
jQuery 8년 전 조회 1,450
jQuery 8년 전 조회 1,561
jQuery 8년 전 조회 1,786
jQuery 8년 전 조회 2,019
jQuery 8년 전 조회 1,555
jQuery 8년 전 조회 1,489
jQuery 8년 전 조회 1,583
jQuery
[jQuery]
8년 전 조회 1,467
jQuery 8년 전 조회 1,596
jQuery 8년 전 조회 1,644
jQuery 8년 전 조회 1,659
jQuery 8년 전 조회 1,845
jQuery 8년 전 조회 1,776
jQuery 8년 전 조회 1,638
jQuery 8년 전 조회 1,708
jQuery 8년 전 조회 1,505
jQuery
[jQuery]
8년 전 조회 1,469
jQuery
[jQuery]
8년 전 조회 1,671
🐛 버그신고