2011-09-28 100 views
0

IM使用一個jQuery + Ajax的工具提示,顯示框,顯示通AJAX的背景下,但提示框的標題設置爲「kbay.in」,並在「」標籤的文本現在,,我要如何改變它顯示標題爲值,ID,姓名,或「一」標籤的其他幹啥,比它的文本:了jQuery,Ajax的工具提示幫助

$(this).qtip(
    { 
     content: { 
      // Set the text to an image HTML string with the correct src URL to the loading image you want to use 
      text: '<img class="throbber" src="http://www.craigsworks.com/projects/qtip/images/throbber.gif" alt="Loading..." />', 
      ajax: { 
       url: $(this).attr('rel') // Use the rel attribute of each element for the url to load 
      }, 
      title: { 
       text: 'Kbay.in' + $(this).name(), // Give the tooltip a title using each elements text 
       button: true 
      } 
     }, 

回答

0

喜歡這個?

title: { 
    text: $(this).prop('value'); // this is the 'value'.. for example 
} 
0

我認爲你正在尋找$(this).attr("name");

$(this).attr("id");

等等等等

+0

使用'代替prop'。 http://stackoverflow.com/questions/5874652/prop-vs-attr – wanovak

+0

其實也沒什麼,使用ATTR。閱讀實際的文檔。 http://api.jquery.com/prop/ VS http://api.jquery.com/attr/ – Evan

+0

你要訪問DOM * *財產。在這種情況下,jQuery將屏蔽你的真相。 – wanovak

0

首先,確保$(本)其實是你的 「a」 元素,讓你知道你抓住了正確的價值。一旦你知道那是肯定的,下面的代碼應該可以幫助您:

<a id="mylink" class="foo" href="blah.html">Testing link text</a> 

var _link = $(this); // Helps keep track of $(this) 

_link.qtip(
    { 
     ... 
     title: { 
      text: 'Kbay.in ' + _link.text(),    // Kbay.in Testing link text 
      // text: 'Kbay.in ' + _link.attr('id'),  // Kbay.in mylink 
      // text: 'Kbay.in ' + _link.attr('href'), // Kbay.in blah.html 
      // text: 'Kbay.in ' + _link.attr('class'), // Kbay.in foo 
      button: true 
     } 
    } 

$的.text()和$ .value的()抓住無論是你的鏈接的打開和關閉標籤之間沒有 HTML作爲反對$的.html()方法返回的標記:

// $(this).text() = "Testing link text" 
// $(this).html() = "Testing link text" 
<a href="blah.html">Testing link text</a>    

// $(this).text() = "Testing link text" 
// $(this).html() = "Testing <b>link</b> text" 
<a href="blah.html">Testing <b>link</b> text</a>