jquery에서 테이블 짝수, 홀수 번째 TR 배경색 변경하기 > jquery

본문 바로가기
사이트 내 전체검색

jquery

jquery에서 테이블 짝수, 홀수 번째 TR 배경색 변경하기

페이지 정보

작성자 서방님 댓글 0건 조회 142회 작성일 15-09-01 16:30

본문

jquery에서  테이블(표) 짝수 또는 홀수 번째 TR 배경색 변경하는 방법입니다.
 
<script>
$(document).ready(function(){
  $('table tr:odd').css("backgroundColor","#fff");         // odd 홀수
  $('table tr:even').css("backgroundColor","#f5f5fc");   // even 짝수
}); 
</script>
 
또는
$(document).ready(function(){
   jQuery('tr').each(function(i) { 
      this.style.backgroundColor = (i % 2) ? 'red' : 'blue'; 
   }); 
}); 
 
※ class 사용
  $('.tr_bg:odd').css("backgroundColor","#fff"); 


<script type="text/javascript">
<!--
/********************************************************************************
* 테이블 <tr> 배경색 설정 (오태정, 2015-09-01 오후 5:03)
********************************************************************************/
$(document).ready(function(){
/*
$(".sub_table tr:odd").css("backgroundColor","#fff"); // odd 홀수
  $(".sub_table tr:even").css("backgroundColor","#f5f5fc"); // even 짝수
*/

$(".sub_table tr").each(function(i) {
this.style.backgroundColor = (i % 2) ? "#fff" : "#f5f5fc";
});
});
//-->
</script>

댓글목록

등록된 댓글이 없습니다.

Total 193건 12 페이지
게시물 검색

회원로그인

접속자집계

오늘
115
어제
225
최대
1,347
전체
154,874
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.