javascript - 如何在cluetip中引用trigger元素?

标签 javascript cluetip

我有以下代码。我想引用触发元素并在 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) {
    }
});
}

最佳答案

来自 the docs

    // 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
        }
    });
});

关于javascript - 如何在cluetip中引用trigger元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16112612/

相关文章:

jquery - 为什么我在使用线索提示时看到两次关闭按钮

javascript - 在缩放级别 3 隐藏谷歌地图中的标记

javascript - 如何在不刷新页面的情况下使用 JavaScript 从 window.location (URL) 中删除哈希?

javascript - 如何通过外部控件/事件启动/停止 jCarousel

javascript - 使用合成鼠标事件驱动 Javascript 代码

jquery - 线索提示在同一地点打开

jquery - jquery有什么方法可以让escape键关闭粘性工具提示吗?

javascript - 在 ng-model 上应用 parseFloat

javascript - native 形式的自定义输入元素

javascript - 在javascript中删除数组中的特定元素