'document.getElementById'에 해당되는 글 1건

  1. 2017.08.22 textarea에 글 내용 길이 구하기 & 빈 값인지 체크하기

        if(document.getElementById("sample_txt").value.length == 0) {

           document.getElementById("add_file").style.display = "none";

        }


일단, if 조건문에 들어간 


document.getElementById("sample_txt").value.length


이 바로 sample_txt라는 ID를 갖은 Textarea의 길이를 구하는 문법이다.

자바스크립트에서는 document.getElementById으로 아이디를 구할 수 있다.


참고로, if문 안에서 실행되는  내용은


add_file이라는 ID를 갖은 엘리먼트를 사라지게(display=none) 만드는 코드이다.

정리하면,

sample_txt의 내용이 비었다면 add_file가 사라지도록 만드는 코드이다.

이것을 


window.onload = function()

      {

        loadContent();

      }


이러한 함수를 만들어 window.onload에 넣고 실행을 한다면, 

해당 페이지가 실행되자마자 loadContent()함수가 실행되게 된다. 



Posted by sungho88
,