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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4556 | jQuery |
프로그래머7
|
8년 전 | 1690 | |
| 4555 | jQuery |
프로그래머7
|
8년 전 | 1606 | |
| 4554 | jQuery |
프로그래머7
|
8년 전 | 1660 | |
| 4553 | jQuery |
프로그래머7
|
8년 전 | 2040 | |
| 4552 | PHP | 8년 전 | 1879 | ||
| 4551 | PHP | 8년 전 | 1464 | ||
| 4550 | PHP | 8년 전 | 1706 | ||
| 4549 | jQuery |
프로그래머7
|
8년 전 | 2743 | |
| 4548 | jQuery |
프로그래머7
|
8년 전 | 1439 | |
| 4547 | jQuery |
프로그래머7
|
8년 전 | 1365 | |
| 4546 | jQuery |
프로그래머7
|
8년 전 | 1683 | |
| 4545 | jQuery |
프로그래머7
|
8년 전 | 1709 | |
| 4544 | jQuery |
프로그래머7
|
8년 전 | 1862 | |
| 4543 | jQuery |
프로그래머7
|
8년 전 | 1651 | |
| 4542 | jQuery |
프로그래머7
|
8년 전 | 1583 | |
| 4541 | jQuery |
프로그래머7
|
8년 전 | 1632 | |
| 4540 | jQuery |
프로그래머7
|
8년 전 | 1665 | |
| 4539 | jQuery |
프로그래머7
|
8년 전 | 1862 | |
| 4538 | jQuery |
프로그래머7
|
8년 전 | 1535 | |
| 4537 | jQuery |
프로그래머7
|
8년 전 | 1695 | |
| 4536 | jQuery |
프로그래머7
|
8년 전 | 1933 | |
| 4535 | jQuery |
프로그래머7
|
8년 전 | 1519 | |
| 4534 | jQuery |
프로그래머7
|
8년 전 | 1854 | |
| 4533 | jQuery |
프로그래머7
|
8년 전 | 2342 | |
| 4532 | jQuery |
프로그래머7
|
8년 전 | 1913 | |
| 4531 | PHP |
|
8년 전 | 3706 | |
| 4530 | jQuery |
프로그래머7
|
8년 전 | 1799 | |
| 4529 | jQuery |
프로그래머7
|
8년 전 | 1898 | |
| 4528 | jQuery |
프로그래머7
|
8년 전 | 1694 | |
| 4527 | jQuery |
|
8년 전 | 2695 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기