0

我正在尝试动态构建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>

仅供参考,这是 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>
4

1 回答 1

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
    });
});​
于 2012-08-22T16:18:58.913 回答