Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML DOM 저장 길이 속성

<시간/>

HTML DOM 저장소 길이 속성은 브라우저의 저장소 개체 내부에 있는 항목 수를 가져오는 데 사용됩니다. 저장소 개체는 localStorage 개체 또는 sessionStorage 개체일 수 있습니다.

구문

다음은 −

의 구문입니다.

localStorage 객체를 사용한 저장 길이 속성 -

localStorage.length;

sessionStorage 객체를 사용한 저장 길이 속성

sessionStorage.length;

예시

Storage length 속성에 대한 예를 살펴보겠습니다. -

<!DOCTYPE html>
<html>
<body>
<h1 style="text-align:center">Storage length property example</h1>
<p>Get how many storage items are stored in the local storage object by clicking the below button</p>
<button onclick="itemNum()">GET NUMBER</button>
<p id="Sample"></p>
<script>
   function itemNum() {
      var num = localStorage.length;
      document.getElementById("Sample").innerHTML = "Number of storage items are "+num;
   }
</script>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

HTML DOM 저장 길이 속성

GET NUMBER -

를 클릭하면

HTML DOM 저장 길이 속성