2013-11-04 3 views
0

이 jQuery 코드는 1.6.4 버전을 제외한 모든 jQuery 버전에서 배경색을 변경합니다. 1.6.4 버전에서이 코드가 제대로 실행되지 않는 이유는 무엇입니까?jQuery의 활성 배경색 전환 1.6.4

HTML :

<table cellspacing="0" cellpadding="0" id="bin" width="100%"> 
    <thead> 
     <tr> <a href="#"><th style="text-align:left; padding-top: 20px;" width="10%" id="row-1">Symbol <img src="/images/sort-arrow-up.png" title="Sort by Symbol" alt="Sort by Symbol" class="sort-right move-left bottom-image" id="image1"/></th></a> 

      <th style="text-align:left;" width="20%" id="row-2">Company 
       <br><span class="move_right">Name</span> 
       <img src="/images/sort-arrow-up.png" title="Sort by Company Name" alt="Sort by Company Name" class="sort-right move-left" id="image2" /> 
      </th> 
      <th style="text-align:center;" width="12%" id="row-3"><span class="center-text">Buy</span> 
       <br>Date 
       <img title="Sort by Buy Date" src="/images/sort-arrow.png" alt="Sort by Buy Date" id="image3" /> 
      </th> 
      <th style="text-align:center;" width="10%" id="row-4"><span class="center-text">Buy</span> 
       <br>Price &nbsp; 
       <img title="Sort by Buy Price" src="/images/sort-arrow.png" alt="Sort by Buy Price" id="image4" /> 
      </th> 
      <th style="text-align:center;" width="9%" id="row-5"><span class="center-text">Closed</span> 
       <br>Price &nbsp; 
       <img title="Sort by Closed Price" src="/images/sort-arrow.png" alt="Sort by Closed Price" id="image5" /> 
      </th> 
      <th style="text-align:center;" width="9%" id="row-6"><span class="center-text">Closed</span> 
       <br>Date &nbsp; 
       <img title="Sort by Closed Date" src="/images/sort-arrow.png" alt="Sort by Closed Date" id="image6" /> 
      </th> 
      <th style="text-align:center;" width="10%" id="row-7"><span class="center-text">Total</span> 

jQuery를 :

$(function(){ 
    $('#bin').on('click', 'th', function(){ 
     $(this).parent().children().removeClass('active'); 
     $(this).addClass('active'); 
    }); 
}); 

CSS :

tr th.active 
{ 
    background-color: #7DAFFF;!important 
} 

DEMO-jsFiddle

답변

1

나는

여기

http://jsperf.com/on-vs-delegate-jquery/3

.delegate는 나중에 그들은 그것을 변경 1.6.4에서 작동합니다 라이브러리 1.6.4 이후

사이 한 차이가있어 CSTE 연구진은 jQuery를 1.6.4 인식하지 않은 것 같아요 여기 CSTE 연구진

것이 클릭으로 인 (함수()

$(function(){ 
     $('#bin th').click(function(){ 
      $(this).parent().children().removeClass('active'); 
      $(this).addClass('active'); 
     }); 
    }); 
,174

EXAMPLE

+0

고마워요, 고마워요, 고마워요! @SzymonDzieqoriski –

+0

맞습니다. 1.7 이상에서만 지원됩니다. 문서 http://api.jquery.com/on#on1에 바로 여기 있습니다. – TreeTree

+0

문제 없음, 도움이 되서 기쁩니다 :) 평화 –

0

내가 시도 그것은이 (fiddle) 추천하고 잘 작동 :

JS :

$(function(){ 
    $('#bin th').click(function(){ 
     $(this).addClass('active').siblings().removeClass('active'); 
    }); 
}); 

CSS :

tr th.active 
{ 
    background-color: #7DAFFF; 
} 

그것이 문제의 원인이 된 CSTE 연구진 방법이었다 낸다.

+0

을 사용할 수 있습니다 JQuery와 1.6.4에서 지원되지 않습니다 당신은 테스트를 해당 버전 1.9.1이 아닌 1.6.4 @Baszz –

+0

@PixelReaper 내 나쁜 ... 업데이트 링크 및 코드 . –

0

당신이 delegate('th','click')