제이쿼리 .attr (attributeName)
제이쿼리 .attr (attributeName)
설명 : 일치하는 요소 세트의 첫 번째 요소에 대한 속성 값을 가져옵니다.
이 .attr()메서드는 일치하는 집합 의 첫 번째 요소에 대해서만 특성 값을 가져옵니다 . 각 요소의 값을 개별적으로 가져 오려면 jQuery .each()또는 .map()메서드 와 같은 루핑 구문을 사용하십시오 .
jQuery의 .attr()메서드를 사용 하여 요소의 속성 값을 얻는 데는 두 가지 주요 이점이 있습니다.
편리 성 : jQuery 객체에서 직접 호출 할 수 있고 다른 jQuery 메소드와 연결될 수 있습니다.
브라우저 간 일관성 : 일부 속성의 값은 브라우저간에 일관성없이보고되고 단일 브라우저의 여러 버전에서도 일치하지 않습니다. 이 .attr()방법은 이러한 불일치를 줄입니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>attr demo</title>
<style>
p {
margin: 20px 0 0;
}
b {
color: blue;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<input id="check1" type="checkbox" checked="checked">
<label for="check1">Check me</label>
<p></p>
<script>
$( "input" )
.change(function() {
var $input = $( this );
$( "p" ).html( ".attr( 'checked' ): <b>" + $input.attr( "checked" ) + "</b><br>" +
".prop( 'checked' ): <b>" + $input.prop( "checked" ) + "</b><br>" +
".is( ':checked' ): <b>" + $input.is( ":checked" ) + "</b>" );
})
.change();
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4706 | jQuery | 8년 전 | 1516 | ||
| 4705 | jQuery | 8년 전 | 2173 | ||
| 4704 | jQuery | 8년 전 | 1710 | ||
| 4703 | jQuery | 8년 전 | 2045 | ||
| 4702 | jQuery | 8년 전 | 1834 | ||
| 4701 | jQuery | 8년 전 | 2064 | ||
| 4700 | jQuery | 8년 전 | 1746 | ||
| 4699 | jQuery | 8년 전 | 1530 | ||
| 4698 | jQuery | 8년 전 | 1339 | ||
| 4697 | jQuery | 8년 전 | 1754 | ||
| 4696 | jQuery | 8년 전 | 2374 | ||
| 4695 | jQuery | 8년 전 | 1390 | ||
| 4694 | jQuery | 8년 전 | 1800 | ||
| 4693 | jQuery | 8년 전 | 1777 | ||
| 4692 | jQuery | 8년 전 | 2568 | ||
| 4691 | jQuery | 8년 전 | 2076 | ||
| 4690 | jQuery | 8년 전 | 1967 | ||
| 4689 | jQuery | 8년 전 | 1947 | ||
| 4688 | jQuery | 8년 전 | 1705 | ||
| 4687 | jQuery | 8년 전 | 1120 | ||
| 4686 | jQuery | 8년 전 | 1750 | ||
| 4685 | jQuery | 8년 전 | 2495 | ||
| 4684 | jQuery | 8년 전 | 2374 | ||
| 4683 | jQuery | 8년 전 | 1769 | ||
| 4682 | PHP | 8년 전 | 3089 | ||
| 4681 | jQuery | 8년 전 | 1611 | ||
| 4680 | jQuery | 8년 전 | 1796 | ||
| 4679 | PHP | 8년 전 | 2022 | ||
| 4678 | PHP | 8년 전 | 2154 | ||
| 4677 | PHP | 8년 전 | 2259 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기