[jQuery - 기능 - (3) ] $.var() → value load : 값 추출(로드)
$.var()
val()은 양식(form)의 값을 가져오거나 값을 설정하는 메소드입니다.
기본 형식 - (1)
1
|
var jb = $( 'input#jbInput' ).val();
|
: ID명이 jbInput인 input 요소의 값을 변수 jb에 저장합니다.
기본 형식 - (2)
1
|
$( 'input#jbInput' ).val( 'ABCDE' );
|
: ID명이 jbInput인 input 요소의 값을 ABCDE로 정합니다.
예제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready( function() {
$( 'button#jbInputButton' ).on("click", function() {
var jb = $( 'input#jbInput' ).val();
alert( jb );
} );
} );
</script>
</head>
<body>
<p><input type="text" id="jbInput"> <button id="jbInputButton">Click</button></p>
</body>
</html>
Color Scripter
|
코드 실행 : https://www.w3schools.com/code/tryit.asp?filename=G6D6025878R0
'◽ HTML & CSS & JS, jQuery' 카테고리의 다른 글
[jQuery - 기능 - (5) ] $.validate() - (2) : errorPlacement - validate 메시지 위치 설정하기 (0) | 2019.08.13 |
---|---|
[jQuery - 기능 - (5) ] $.validate() - (1) : 유효성 검사 [ 확인 문구 바로 출력 ] (0) | 2019.08.12 |
[jQuery - 기능 - (4) ] $.each() → 반복 함수 (0) | 2019.08.12 |
[jQuery - 기능 - (2) ] $.on() → event bind ( 1.7 ver.) : 이벤트 설정 (0) | 2019.08.12 |
[jQuery - 기능 - (1) ] $.ready() = $(document).ready(function(){ }) (0) | 2019.08.12 |
[CSS] ::before ::after은 무엇인가? (0) | 2019.08.03 |
[JavaScript - (8) ] document.getElementById( ) - 자바스크립트 id 접근 (0) | 2019.07.30 |