jQuery.data()
jQuery.data()
지정된 요소와 관련된 임의의 데이터를 저장하거나 설정된 값을 반환합니다.
이 jQuery.data()방법을 사용하면 순환 참조로부터 안전하고 메모리 누수가없는 방식으로 DOM 요소에 모든 유형의 데이터를 첨부 할 수 있습니다. jQuery는 jQuery 메서드를 통해 DOM 요소를 제거하고 사용자가 페이지를 떠날 때 데이터가 제거되도록합니다. 하나의 요소에 대해 여러 개의 고유 한 값을 설정하고 나중에 검색 할 수 있습니다.
jQuery.data( document.body, "foo", 52 );
jQuery.data( document.body, "bar", "test" );
추가 참고 사항 :
Internet Explorer에서는 확장 속성을 통해 데이터를 첨부 할 수 없으므로이 메서드는 현재 XML 문서의 데이터 설정을위한 플랫폼 간 지원을 제공하지 않습니다.
undefined데이터 값으로 인식되지 않습니다. 와 같은 호출 jQuery.data( el, "name", undefined )은 "이름"에 해당하는 데이터를 리턴 할 것이기 때문에와 같습니다 jQuery.data( el, "name" ).
예:
그런 다음 저장소는 div 요소에서 값을 검색합니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.data demo</title>
<style>
div {
color: blue;
}
span {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div>
The values stored were
<span></span>
and
<span></span>
</div>
<script>
var div = $( "div" )[ 0 ];
jQuery.data( div, "test", {
first: 16,
last: "pizza!"
});
$( "span:first" ).text( jQuery.data( div, "test" ).first );
$( "span:last" ).text( jQuery.data( div, "test" ).last );
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4586 | jQuery |
프로그래머7
|
8년 전 | 2088 | |
| 4585 | PHP | 8년 전 | 2159 | ||
| 4584 | PHP | 8년 전 | 2411 | ||
| 4583 | PHP | 8년 전 | 2354 | ||
| 4582 | jQuery |
프로그래머7
|
8년 전 | 1425 | |
| 4581 | jQuery |
프로그래머7
|
8년 전 | 1373 | |
| 4580 | jQuery |
프로그래머7
|
8년 전 | 1905 | |
| 4579 | PHP | 8년 전 | 2229 | ||
| 4578 | PHP | 8년 전 | 1740 | ||
| 4577 | PHP | 8년 전 | 2470 | ||
| 4576 | OS |
프로그래머7
|
8년 전 | 2697 | |
| 4575 | PHP | 8년 전 | 1924 | ||
| 4574 | PHP | 8년 전 | 1558 | ||
| 4573 | PHP | 8년 전 | 1966 | ||
| 4572 | PHP | 8년 전 | 2063 | ||
| 4571 | PHP | 8년 전 | 2415 | ||
| 4570 | PHP | 8년 전 | 2273 | ||
| 4569 | jQuery |
프로그래머7
|
8년 전 | 1864 | |
| 4568 | jQuery |
프로그래머7
|
8년 전 | 1402 | |
| 4567 | jQuery |
프로그래머7
|
8년 전 | 1967 | |
| 4566 | jQuery |
프로그래머7
|
8년 전 | 1897 | |
| 4565 | jQuery |
프로그래머7
|
8년 전 | 1648 | |
| 4564 | PHP | 8년 전 | 2578 | ||
| 4563 | PHP | 8년 전 | 1917 | ||
| 4562 | PHP | 8년 전 | 2426 | ||
| 4561 | jQuery |
프로그래머7
|
8년 전 | 1364 | |
| 4560 | jQuery |
프로그래머7
|
8년 전 | 1904 | |
| 4559 | jQuery |
프로그래머7
|
8년 전 | 1449 | |
| 4558 | node.js |
|
8년 전 | 3431 | |
| 4557 | jQuery |
프로그래머7
|
8년 전 | 1727 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기