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

HTML enctype 속성

<시간/>

HTML enctype 속성은 양식 데이터의 인코딩 형식을 지정합니다. post 방식을 사용하면 enctype 속성을 지정할 수 있습니다.

여기서 enctype 속성은 다음과 같은 값을 가질 수 있습니다. -


설명
application/x-www-form-urlencoded
기본값입니다. 모든 문자는 전송되기 전에 인코딩됩니다(공백은 "+" 기호로 변환되고 특수 문자는 ASCII HEX 값으로 변환됨)
멀티파트/양식 데이터
문자를 인코딩하지 않습니다. 사용자가 파일 업로드 컨트롤이 있는 양식을 사용하는 경우 이 값이 필요합니다.
텍스트/일반
이 enctype 값을 사용하면 공백이 "+" 기호로 변환되지만 특수 문자는 인코딩되지 않습니다.

HTML enctype의 예를 살펴보겠습니다. 속성:

예시

<!DOCTYPE html>
<html>
<head>
<title>HTML enctype attribute</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 enctype="multipart/form-data" action="" method="post">
<fieldset>
<legend>HTML-enctype-attribute</legend>
<label for="EmailSelect">Email Id:
<input type="email" id="EmailSelect">
<input type="button" onclick="getUserEmail('david')" value="David">
<input type="button" onclick="getUserEmail('shasha')" value="Shasha"><br>
<input type="button" onclick="login()" value="Login">
</label>
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputEmail = document.getElementById("EmailSelect");
   function getUserEmail(userName) {
      if(userName === 'david')
         inputEmail.value = 'davidMiller@MNC.com';
      else
         inputEmail.value = 'shashaGreen@MNC.com';
   }
   function login() {
      if(inputEmail.value !== '')
         divDisplay.textContent = 'Successful Login. Hello '+inputEmail.value.split("@")[0];
      else
         divDisplay.textContent = 'Enter Email Id';
   }
</script>
</body>
</html>

출력

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

1) '로그인' 클릭 이메일 필드가 비어 있는 버튼 -

HTML enctype 속성

2) '로그인' 클릭 후 이메일 필드가 설정된 버튼 -

HTML enctype 속성