Js 입력에서 값 가져 오기

코드 예제

51
0

자바 스크립트 텍스트 입력 값 가져 오기

var inputValue = document.getElementById("myTextInputID").value;
17
0

값 자바 스크립트 가져 오기

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get Text Input Field Value in JavaScript</title>
</head>
<body>
    <input type="text" placeholder="Type something..." id="myInput">
    <button type="button" onclick="getInputValue();">Get Value</button>
    
    <script>
        function getInputValue(){
            // Selecting the input element and get its value 
            var inputVal = document.getElementById("myInput").value;
            
            // Displaying the value
            alert(inputVal);
        }
    </script>
</body>
</html>
2
0

입력 js 의 값 가져 오기

<!-- for simplicity's sake, I have the js code and html in the same file -->
<!-- if you want to, you can add the js in another file and make a <script> tag and link it up to the html file -->

<html lang="en">
<head>
<meta charset="utf-8">
<title>Get Text Input Field Value in JavaScript</title>
</head>
<body>
    <input type="text" placeholder="Type something..." id="myInput">
    <button type="button" onclick="getInputValue();">Get Value</button>
    
    <script>
        function getInputValue(){
            // Selecting the input element and get its value 
            var inputVal = document.getElementById("myInput").value;
            
            // Displaying the value
            alert(inputVal);
        }
    </script>
</body>
</html>
2
0

js 양식 입력에서 값 가져 오기

// having form like this

<form>
  <div>
  	<label for="number">Give me number</label>
	<input type="number" id="number">
  </div>
  <div>
    <button class="btn">Click</button>
  </div>
</form>

// this is how u get a value (number)
document.querySelector("form").addEventListener("submit", get_number);
function get_number(e){
    const n = document.getElementById("number").value;
    console.log('n:', n)
    e.preventDefault();
}

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................