2011-09-28 107 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>