3

我想在我的页面上的 iFrame 中找到一个使用 Qtip 的方法。我找到了一种在 iframe 上使用 QTIP 的方法,但不适用于 JQUERY LIVE ....

qTip 通过 iFrame:http: //craigsworks.com/projects/forums/thread-question-qtip-through-iframe

关于如何将 JQUERY Live 应用于此的任何想法?

我当前的代码:

$('iframe').load(function(){
  $(this).qtip(
  {
    content: 'My first Qtip! Look mom!',
    show: {
      when : {
         target: $(this).contents().find('.tipoff') // Element within the iframe
      }
    },
    hide: {
      when : {
         target: $(this).contents().find('.tipoff') // Element within the iframe
      }
    }
  });
});

谢谢

4

1 回答 1

1

我知道这已经快一年了,但我只是想做类似的事情,并认为我会发布我的发现。我不完全确定你在追求什么,它可能与我所拥有的不同,但我假设你想像我一样对动态加载的某些元素应用qTip<iframe>

它没有解决live()问题,即使根据使用 jQuery (live?) 在 iF​​rame 中添加一行到表中它应该可以工作,但这是我最终得到的结果:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        iframe {
            border:1px dashed red;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="jquery.qtip.min.css"/>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script src="jquery.qtip.min.js"></script>
    <script type="text/javascript">

        $(function() {
            $('p a.tip').qtip({
                content: 'foo'
            });

            $('iframe').load(function() {
                var position = $(this).position();
                var top = position.top;
                var left = position.left;
                $(this.contentDocument).find('p a.tip').qtip({
                    content: 'bar',
                    position: { adjust: { x:left, y:top } }
                });
            });

            $('#click').click(function(){
                $('iframe').attr('src', 'test.html');
                return false;
            });
        });

    </script>
</head>
<body>
    <p><a class="tip" href="#">Lorem ipsum dolor</a> sit amet, consectetur adipiscing elit.</a></p>
    <iframe></iframe>
    <p><a href="#" id="click">Load iFrame</a></p>
</body>
</html>

其中 test.html 包含:

<p><a class="tip" href="#">Duis massa metus</a>, convallis vitae, mollis vel, feugiat vitae, nunc.</p>

您可以从qTip2jquery.qtip.min.css获取和获取。jquery.qtip.min.js

编辑:确保页面是从 Web 服务器加载到浏览器中的(不仅仅是作为本地文件加载),以避免出现Same origin policy

希望这对某人有用!:-)

于 2011-04-12T13:17:51.830 回答