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

HTML 입력 읽기 전용 속성

<시간/>

HTML 입력 읽기 전용 속성은 여전히 ​​복사될 수 있지만 수정할 수 없는 입력 요소를 선언하는 데 사용됩니다.

읽기 전용 입력의 예를 살펴보겠습니다. 속성 -

예시

<!DOCTYPE html>
<html>
<head>
<title>Input Email readOnly</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Email-readOnly</legend>
<label for="EmailSelect">Contact Us :
<input type="email" id="EmailSelect" onclick="showErrorMsg()" value="infoHelpDesk@MNC.com" readOnly>
</label>
<input type="button" onclick="showMessage()" value="Copy Email Id">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputEmail = document.getElementById("EmailSelect");
   divDisplay.textContent = 'Above email is read-only';
   function showMessage() {
      inputEmail.select();
      document.execCommand('copy');
      divDisplay.textContent = 'Email Copied: '+inputEmail.value;
   }
   function showErrorMsg(){
      divDisplay.textContent +=', This cannot be edited.'
   }
</script>
</body>
</html>

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

1) '이메일 ID 복사를 클릭하기 전에 ' 버튼 -

HTML 입력 읽기 전용 속성

2) '문의하기 클릭 ' 이메일 필드 -

HTML 입력 읽기 전용 속성

3) '이메일 ID 복사 클릭 ' -

HTML 입력 읽기 전용 속성