값을 포함하는 몇 가지 입력 필드가있는 웹 페이지가 있습니다.
<input type="text" id="input_1" value="Apple">
<input type="text" id="input_2" value="Pear">
이 값을 추출하고 다음과 같은 배열에 저장하려면 Javascript / jQuery가 필요합니다.
var myArray = ["Apple", "Pear"];
누구든지 이것을하는 방법을 알고 있습니까?
감사!
당신은 jQuery를 사용 map()
하고 get()
값의 배열을 반환 할 수 있습니다.
var myArray = $('input[type="text"]').map(function() {
return this.value;
}).get();
console.log(myArray)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<input type="text" id="input_1" value="Apple">
<input type="text" id="input_2" value="Pear">
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다