我不知道我在这里做错了什么。我想用一些data-*
属性作为jQuery UI工具提示的内容。使用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
@swajak这是一个经过编码的内容,从上面的行中删除注释,以便将文本属性作为文本使用 –