2011-07-06 3 views
3

jQuery qTips를 호출하는 태그의 "id"속성을 가져 오려고합니다. 다음과 같이 설정은 다음과 같습니다jquery qTips에서 선택기 속성을 얻는 방법?

$('.selector').qtip({ 
    content: { 
     text: 'Loading...', // The text to use whilst the AJAX request is loading 
     ajax: { 
     url: 'getInfo.php', // URL to the local file 
     type: 'GET', // POST or GET 
     async: false, 
     data: { id: $(this).attr('id')}, // !! PROBLEM HERE 
     success: function(data, status) { 

      // Set the content manually (required!) 
      this.set('content.text', data); 
     } 
     } 
    } 

}); 

발신자는 다음과 같은 수 있습니다 :

<a href='http://www.google.com' class='selector' id='Jerome'>Jerome</a> 

하지만 어떤 이유로 $에 대한

(이) .attr ("ID")가 정의되어 있지 않습니다. qTip은 나타나지만 공백이며 GET 호출은 Firebug에서 아무 데이터도 전달하지 않는 것으로 나타납니다. 내가 뭘 놓치고 있니?

감사합니다.

편집 : 또한, 여전히 플러그인을 qtip에 전달되는 JSON 객체를 구성하기 때문에이 현재 요소를 가리키는되지

+0

어떤 qtip 버전을 사용하고 있습니까? –

+0

야간 빌드, v2? – Rio

답변

3

이 문제를 해결할 것이보십시오.

$('.selector').each(function(index, item){ 
    $(item).qtip({ 
    content: { 
     text: 'Loading...', // The text to use whilst the AJAX request is loading 
     ajax: { 
     url: 'getInfo.php', // URL to the local file 
     type: 'GET', // POST or GET 
     async: false, 
     data: { id: $(item).attr('id')}, // !! PROBLEM HERE 
     success: function(data, status) { 

      // Set the content manually (required!) 
      this.set('content.text', data); 
     } 
     } 
    } 

}); 

});

+0

@ 리오 - 도움이 되었습니까? – ShankarSangoli

+0

이것은 효과가 있습니다. 감사! – Rio

0

"함수 아니다 this.attr"this.attr 돌아갑니다. 동일한 선택기를 사용하여 jquery 객체를 가져와야합니다. 이것에 대해

$('.selector').qtip({ 
    content: { 
     text: 'Loading...', // The text to use whilst the AJAX request is loading 
     ajax: { 
     url: 'getInfo.php', // URL to the local file 
     type: 'GET', // POST or GET 
     async: false, 
     data: { id: $('.selector').attr('id')}, // !! PROBLEM HERE 
     success: function(data, status) { 

      // Set the content manually (required!) 
      this.set('content.text', data); 
     } 
     } 
    } 

}); 
+0

'.selector'가 여러 개 있으면 어떨까요? 각각은 서로 다른 ID를가집니다. – Rio

+0

그런 다음 ID가 고유 한 요소에 더 잘 액세스합니다. 또는 해당 ID를 모두 선택하고 각 루프를 사용하여 플러그인을 초기화하십시오. – ShankarSangoli

+0

ID가 다른 것들을 묶어서 코드를 다시 작성하기 때문에 이는 다소 비효율적입니다. – Rio

0

무엇 :

$('.selector').each(function() { 
     var thisId = $(this).attr("id"); 
     $(this).qtip({ 
      content: { 
       text: 'Loading...', // The text to use whilst the AJAX request is loading 
       ajax: { 
        url: 'getInfo.php', // URL to the local file 
        type: 'GET', // POST or GET 
        async: false, 
        data: { id: thisId }, // !! PROBLEM HERE 
        success: function (data, status) { 

         // Set the content manually (required!) 
         this.set('content.text', data); 
        } 
       } 
      } 
     }); 
    });