[HTML] input_ readonly vs disabled

Chaewon Yoon (Jamie)·2023년 1월 3일

Tips for HTML

목록 보기
1/3

input에 입력하지 못하게 막는 법

  1. readonly
  2. disabled

사용법

<input type="text" id="txt1" readonly />        

<input type="text" id="txt2" disabled />



<textarea id="txtfield1" readonly ></textarea>

<textarea id="txtfield2" disabled ></textarea>



<input type="password" id="pass1" readonly />

<input type="password" id="pass2" disabled />


readonly vs disabled

  • readonly인 경우는 사용자가 입력을 할 수 없고, 값이 전달된다.

  • disabled인 경우는 사용자가 입력을 할 수 없고, 값이 아예 전달되지 않는다.
    컨트롤러로 값을 전달해서 사용할 수 없다.

disabled는 아예 값을 사용하지 못하게 하는데, readonly는 값을 읽어올 수 있다는 차이점이 있다.

나의 경우에는 컨트롤러로 값을 전달해야 하므로 readonly를 사용했다.

profile
keep growing as a web developer!🧃

0개의 댓글