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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4796 | jQuery | 8년 전 | 1534 | ||
| 4795 | jQuery | 8년 전 | 1436 | ||
| 4794 | jQuery | 8년 전 | 1562 | ||
| 4793 | jQuery | 8년 전 | 1620 | ||
| 4792 | jQuery | 8년 전 | 1624 | ||
| 4791 | jQuery | 8년 전 | 1794 | ||
| 4790 | jQuery | 8년 전 | 1735 | ||
| 4789 | jQuery | 8년 전 | 1598 | ||
| 4788 | jQuery | 8년 전 | 1660 | ||
| 4787 | jQuery | 8년 전 | 1475 | ||
| 4786 | jQuery | 8년 전 | 1434 | ||
| 4785 | jQuery | 8년 전 | 1645 | ||
| 4784 | jQuery | 8년 전 | 1521 | ||
| 4783 | jQuery | 8년 전 | 1229 | ||
| 4782 | jQuery | 8년 전 | 1598 | ||
| 4781 | jQuery | 8년 전 | 1338 | ||
| 4780 | jQuery | 8년 전 | 1575 | ||
| 4779 | jQuery | 8년 전 | 1983 | ||
| 4778 | jQuery | 8년 전 | 1957 | ||
| 4777 | jQuery | 8년 전 | 1528 | ||
| 4776 | jQuery | 8년 전 | 1582 | ||
| 4775 | jQuery | 8년 전 | 1971 | ||
| 4774 | jQuery | 8년 전 | 1484 | ||
| 4773 | jQuery | 8년 전 | 1410 | ||
| 4772 | jQuery | 8년 전 | 2203 | ||
| 4771 | jQuery | 8년 전 | 3609 | ||
| 4770 | PHP | 8년 전 | 5579 | ||
| 4769 | 기타 | 8년 전 | 1962 | ||
| 4768 | 기타 | 8년 전 | 1781 | ||
| 4767 | 기타 | 8년 전 | 2066 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기