我知道这已经快一年了,但我只是想做类似的事情,并认为我会发布我的发现。我不完全确定你在追求什么,它可能与我所拥有的不同,但我假设你想像我一样对动态加载的某些元素应用qTip<iframe>
。
它没有解决live()
问题,即使根据使用 jQuery (live?) 在 iFrame 中添加一行到表中它应该可以工作,但这是我最终得到的结果:
<!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。
希望这对某人有用!:-)