【发布时间】:2014-04-26 00:46:36
【问题描述】:
我不确定我在这里做错了什么。我想使用一些 data-* 属性作为 jQuery UI 工具提示的内容。
我在这个答案中看过几个例子:
但我不能让它正常工作......
这是我的代码:
FIDDLE: http://jsfiddle.net/P2XhC/
HTML
<div id="div_1">number 1</div>
<div id="div_2">number 2</div>
<div id="div_3">number 3</div>
<button id="btn_class">STEP 1: Add class to 1 and 3</button>
<button id="btn_tooltip">STEP 2: Add tooltip to class</button>
<button id="btn_check">STEP 3: Check for data</button>
JS
$("#btn_class").click(function()
{
$("#div_1, #div_3").addClass("tooltip").data("text", "show this!");
});
$("#btn_tooltip").click(function()
{
$(".tooltip").tooltip({
//content: $(this).data("text"), //this doesn't work
content: "show something...", //this works!
items: '*'
});
});
$("#btn_check").click(function()
{
$("div").each(function()
{
console.log($(this).attr("id") + " = " + $(this).data("text");
});
});
CSS
.tooltip
{
color: red;
}
【问题讨论】:
-
当我将鼠标悬停在工具提示上时会看到它们。这里有什么问题?
-
@swajak 这是一个硬编码的内容,请从上面的行中删除注释以便将数据属性用作文本
标签: jquery jquery-ui jquery-ui-tooltip