1

我有以下代码。我想引用触发器元素并在 onShow() 中获取标记值。我怎样才能做到这一点?谢谢

<a class="tips" tag="12">TEST 01</a>
<a class="tips" tag="123">TEST 02</a>
<a class="tips" tag="1234">TEST 03</a>
<a class="tips" tag="12345">TEST 04</a>

$(document).ready(function () {
$('a.tips').cluetip({
    splitTitle: "|",
    width: '500',
    sticky: true,
    closePosition: 'title',
    dropShadow: true,
    onShow: function (ct, ci) {
    }
});
}
4

1 回答 1

3

文档

    // function to run just after clueTip is shown. It can take two arguments:
    // the first is a jQuery object representing the clueTip element;
    // the second a jQuery object represeting the clueTip inner div.
    // Inside the function, this refers to the element that invoked the clueTip
    onShow:           function(ct, ci){},

因此,您应该使用,this来引用元素。

而且,对于您问题的另一部分,您可以使用 jQuery:

$(document).ready(function () {
    $('a.tips').cluetip({
        splitTitle: "|",
        width: '500',
        sticky: true,
        closePosition: 'title',
        dropShadow: true,
        onShow: function(ct, ci){
            var selectedTag = $(this).attr("tag"); //get the tag
        }
    });
});
于 2013-04-19T20:05:45.683 回答