我有以下代码。我想引用触发器元素并在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) {
}
});
}
答案 0 :(得分:3)
来自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
}
});
});