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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4856 | PHP | 7년 전 | 5740 | ||
| 4855 | jQuery | 7년 전 | 3246 | ||
| 4854 | jQuery | 7년 전 | 2237 | ||
| 4853 | jQuery | 7년 전 | 2842 | ||
| 4852 | MySQL | 7년 전 | 3000 | ||
| 4851 | jQuery | 7년 전 | 2349 | ||
| 4850 | jQuery | 7년 전 | 2578 | ||
| 4849 | jQuery | 7년 전 | 4316 | ||
| 4848 | PHP |
|
7년 전 | 4251 | |
| 4847 | jQuery | 7년 전 | 4025 | ||
| 4846 | jQuery | 7년 전 | 2649 | ||
| 4845 | jQuery | 7년 전 | 2163 | ||
| 4844 | jQuery | 8년 전 | 2311 | ||
| 4843 | jQuery | 8년 전 | 3062 | ||
| 4842 | jQuery | 8년 전 | 2908 | ||
| 4841 | jQuery | 8년 전 | 2235 | ||
| 4840 | jQuery | 8년 전 | 1576 | ||
| 4839 | jQuery | 8년 전 | 2474 | ||
| 4838 | jQuery |
이에스씨코리아
|
8년 전 | 2327 | |
| 4837 | jQuery | 8년 전 | 2175 | ||
| 4836 | jQuery | 8년 전 | 2100 | ||
| 4835 | jQuery | 8년 전 | 1837 | ||
| 4834 | jQuery | 8년 전 | 1875 | ||
| 4833 | jQuery | 8년 전 | 2000 | ||
| 4832 | jQuery | 8년 전 | 2192 | ||
| 4831 | jQuery | 8년 전 | 2371 | ||
| 4830 | jQuery | 8년 전 | 2637 | ||
| 4829 | jQuery | 8년 전 | 1810 | ||
| 4828 | jQuery | 8년 전 | 2755 | ||
| 4827 | jQuery | 8년 전 | 2296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기