수

jQuery ( ": focus")

· 2017-09-29 (금) 22:38:08 · 2283

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>

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

개발자팁

5,403건

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

+
분류 제목 글쓴이 날짜 조회
jQuery 17-10-11 조회 2,489
jQuery 17-10-11 조회 1,958
jQuery 17-10-11 조회 2,061
jQuery 17-09-29 조회 2,284
jQuery 17-09-29 조회 2,519
jQuery 17-09-29 조회 2,064
jQuery 17-09-26 조회 1,990
jQuery 17-09-26 조회 2,079
jQuery
[jQuery]
17-09-26 조회 1,851
jQuery 17-09-22 조회 2,097
jQuery 17-09-22 조회 2,156
jQuery 17-09-22 조회 2,125
jQuery 17-09-21 조회 2,321
jQuery 17-09-21 조회 2,269
jQuery 17-09-21 조회 2,138
jQuery 17-09-19 조회 2,195
jQuery 17-09-19 조회 1,959
jQuery
[jQuery]
17-09-19 조회 1,937
jQuery
[jQuery]
17-09-18 조회 2,102
jQuery 17-09-18 조회 2,016
jQuery 17-09-18 조회 1,712
jQuery 17-09-14 조회 2,136
jQuery 17-09-14 조회 1,820
jQuery 17-09-14 조회 2,059
jQuery 17-09-11 조회 2,454
jQuery 17-09-11 조회 2,486
jQuery 17-09-11 조회 2,006
jQuery 17-09-10 조회 2,066
jQuery 17-09-10 조회 2,503
jQuery
[jQuery]
17-09-10 조회 1,958