0

我想制作一个包含按钮图像的工具提示。

使用此代码可以正常工作:

$( document ).tooltip({
  items: "button",
  content: function() {
       var element = $( this );
       if (element.attr('id') === 'surah') {
           return "<img src='http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Wien_Stefansdom_DSC02656.JPG/450px-Wien_Stefansdom_DSC02656.JPG' />";
       }
    }
});

但有了这个,它没有(我检查了很多次图片路径)

$( document ).tooltip({
  items: "button",
  content: function() {
       var element = $( this );
       if (element.attr('id') === 'surah') {
           return "<img src='../img/home.jpg' />";
       }
    }
});
4

1 回答 1

0

It's your: '../ is a relative path, are you sure that's where the images are, and remember that if your javascript is included from an external file, it's not relative to the .js file, but to the file where it's included.

Try:

if (this.id == 'surah') return 'image.jpg';

Linking paths correctly is very important!

于 2013-06-23T12:39:02.893 回答