• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Property] JQ - length 속성 ★ - 객체의 요소개수 (= length속성 = 렝스속성) ※ 입력 내용 일정 길이 이상 시, 포커스 자동 이동.

목차

  1. length 예제 - li 요소 개수
  2. length 정의
  3. length 구문
  4. length 예제 - 입력 내용 일정 길이 이상 시, 포커스 자동 이동

 

length 예제 - li 요소 개수

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("button").click(function(){

    alert($("li").length);

  });

});

</script>


<button>요소 개수?</button>


<ul>

  <li>홈짱닷컴</li>

  <li>Homzzang.com</li>

  <li>홈페이지제작 + 서버관리</li>

</ul>

 

결과보기

결과값: 3

 

length 정의

 

jQuery 객체의 요소 개수.

 



※ 주의.

JQ 3.0 이상 경우, size() 폐기완료. length 속성으로 대체.

 

 

length 구문

 

$(selector).length

 

※ selector : 선택자 

 

length 예제 - 입력 내용 일정 길이 이상 시, 포커스 자동 이동

 

<input type="tel" id="counsel_tel1" name="counsel_tel1" maxlength="3" class="is3" placeholder="연락처">

 

<script> 

$(function () {

    $('input[name="counsel_tel1"]').keyup(function (e) {

        var thisLen = $(this).val().length;

        if (thisLen >= 3) {

            $('input[name="counsel_tel2"]').focus();

        }

    });

    ....

});

</script>

 

트리플 님 (201102) https://sir.kr/g5_skin/40699


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
게시물이 없습니다.
19/15
목록
찾아주셔서 감사합니다. Since 2012