我正在尝试构建一个href,将其传递到fancybox iframe并将链接传递给php文件
<script type="text/javascript">
jQuery(document).ready(function($){
$('a').each(function(){
var Href = 'GetImg.php?img=' + $(this).attr("href");
alert ("Href");
$(".Images").click(function() {
$.fancybox.open({
href : Href,
type : 'iframe',
padding : 5
});
});
};
}) ; // ready
</script>
正在设置Href即警报(“Href”)并传递到php文件但未在iframe中打开。 如果我硬编码
href : 'GetImg.php?img=/images/myImg.jpg' it works
我的链接是
<a class="Images" href="/images/myImg.jpg" title="A witty Title">Send to PHP</a>
FYI这是GetImg.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>Holly Gibbons</title>
<script type="text/javascript" src="fancyBox-2.0.6/lib/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/ddpowerzoomer.js"></script>
<script type="text/javascript">
jQuery(function($){
$('#image3').addpowerzoom({
defaultpower: 2,
powerrange: [2,5],
largeimage: null,
magnifiersize: [100,100] //<--no comma following last option!
});
});
</script>
</head>
<body>
<?php
$my_img = $_GET['img'];
?>
<p> <img id="image3" src = <?php echo $my_img ?> /></p>
</body>
</html>
答案 0 :(得分:3)
无需选择所有a
标记和循环,您可以像
$(document).on('click', '.Images', function(e) {
e.preventDefault();
var Href = 'GetImg.php?img=' + $(this).attr("href");
alert(Href);
$.fancybox.open({
href: Href,
type: 'iframe',
padding: 5
});
});