2013-09-24 5 views
0

데이터 - 추가 키의 값을 찾으려면 을 클릭하십시오. 버튼을 제거하십시오. 어떻게 할 수 있습니까? 나는 다음과 같은 시도데이터 속성을 사용하여 찾기

<tr class="<%: classNames %>"> 
      <td data-extra-key="<%: item.ServiceKey %>"> 
       <%: item.ServiceName %> 
       for 
       <%: item.PetName %><sub><%: item.Description %></sub> 
      </td> 

      <td> 
       <%if (item.IsAnExtra && !item.IsCancelled) 
        { %> 
       <button class="btnRemoveExtraService actionButton secondaryButton short" type="button" itemid="<%:item.Id%>"> 
        Remove</button> 
       <%} %> 
      </td> 
     </tr> 

(내가와 데이터 속성 찾을 를 사용하는 방법을 모른다) :

$('.btnRemoveExtraService').die('click').live('click', function() { 

        var service= $(this).parents('tr').find('').val(); 

        return false; 

       }); 

답변

1
var dataExtraKey = $(this) 
         .closest('tr')  //find the wrapping <tr> 
         .find('td:first') //traverse down and get the first <td> 
         .data('extra-key'); //get the value 
+1

네 : – Sampath

0

var service= $(this).parents('tr').find('[data-extra-key]').data('extra-key'); 
0

시도 다음과 같이 간단하게 사용할 수 있습니다

  $('.btnRemoveExtraService').die('click').live('click', function() { 

       var service= $(this).parent().parent().find('td:first-child').data('extra-key'); 

       return false; 

      }); 

희망이 있습니다. 그것은 working.Thanks있어,

$('.btnRemoveExtraService').click(function() { 
    var service= $(this).closest('tr').find('td:first').data('extra-key'); 
    return false; 
}); 
0

이 코드를 사용했다.
관련 문제