我對JavaScript很陌生,所以請原諒,如果這是一個愚蠢的問題。JQuery UI工具提示:每個工具提示都有不同的圖像
我試圖爲每個工具提示顯示不同的圖像。 JQuery UI已經設置好了,所以裏面的文字就是圖片的名字。
看看我下面的代碼:
HTML:
<div id="tooltip" class="option-child"><a id="ceramic-pro-rain" title="The Title" data-geo="Rochester" href="#" >• 1 layer of Rain on all windows and glass</a></div>
的JavaScript
<script type="text/javascript">
$(function() {
$(document).tooltip({
//items: "a, [data-geo], [title]",
items: "a",
position: {
my: "left center-29",
at: "right+10 center+18"
},
content: function() {
var element = $(this);
if (element.is("[data-geo]")) {
var text = element.text();
return "<img class='map' alt='" + text +
"' src='http://www.sample.com/img/tooltip/" +
text + ".jpg" + "'>";
}
if (element.is("[title]")) {
return element.attr("title");
}
if (element.is("img")) {
return element.attr("alt");
}
}
});
});
您是基於文本生成'img'元素的'src'屬性。根據條件語句,我想你想根據'[data-geo]'屬性生成它......用'$(this).attr('data-gep 「)'。 –