Jquery, Ajax工具提示帮助



我使用Jquery + Ajax工具提示,它显示一个通过Ajax显示上下文的框,但是工具提示框的标题被设置为"kbay "。在"one_answers"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
            }
        },

像这样?

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

我想你是在找$(this).attr("name");

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

等等

首先,确保$(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>  

最新更新