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

JavaScript에서 버튼을 클릭한 후 내 텍스트 필드를 비워 두는 방법은 무엇입니까?

<시간/>

이를 위해 onclick="yourFunctionName()" 및 -

를 사용할 수 있습니다.
document.getElementById(“”).value=’’

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<input type-="text" id="txtBox" placeholder="Enter the value...."/>
<button type="button" id="clear" onclick="clearTheTextField()">ClearInputText</button>
<script>
   function clearTheTextField(){
      console.log("The text box
      value="+document.getElementById('txtBox').value)
      document.getElementById('txtBox').value = '';
   }
</script>
</body>
</html>

위의 프로그램을 실행하려면 anyName.html(index.html)이라는 파일명을 저장하고 파일을 우클릭하여 VS Code 편집기에서 라이브 서버로 열기 옵션을 선택하면 됩니다.

출력

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

JavaScript에서 버튼을 클릭한 후 내 텍스트 필드를 비워 두는 방법은 무엇입니까?

이제 텍스트 상자에 값을 입력하고 ClearInputText 버튼을 클릭합니다.

JavaScript에서 버튼을 클릭한 후 내 텍스트 필드를 비워 두는 방법은 무엇입니까?

값을 입력한 후 버튼을 클릭합니다.

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

JavaScript에서 버튼을 클릭한 후 내 텍스트 필드를 비워 두는 방법은 무엇입니까?