Jquery,Ajax工具提示帮助

时间:2011-09-28 19:43:56

标签: ajax jquery-ui jquery

即时通讯使用Jquery + Ajax工具提示,显示一个显示通过AJAX的上下文的框,但工具提示框的标题设置为“kbay.in”,文本在“a”标签中,现在怎么做我更改它以将标题显示为“a”标签的值,ID,名称或其他任何内容,而不是其中的文本:

    $(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
            }
        },

3 个答案:

答案 0 :(得分:0)

喜欢这个吗?

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

答案 1 :(得分:0)

我认为您正在寻找$(this).attr("name");

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

等等

答案 2 :(得分:0)

首先,确保$(this)实际上是你的“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>  
相关问题