javascript - 如何通过 jquery fancy box 在框中打开图像

标签 javascript php jquery html css

我想在花式框窗口中打开图像... 我试过这样做...但这不能正常工作

我试过我的代码如下:

$('#show_dialog').click(function() {

    $.fancybox({
        type: 'inline',
        content: '#img_url'
    });
});

通过这个我调用我的花式框窗口:

 <td class="center" style="border:#f4f4f4 1px solid; padding:10px"><a href="#" id="show_dialog" >Show Image</a></td>
    </tr>

这是我要显示的 div:

<div style="display:none;">
    <div id="img_url"> <img src="<?php echo $image_with_url?>" />
    <div style="background:#f4f4f4; color:#00; padding:10px;">
<p style="float:right; font-weight:bold;">Invoice No. : <?php echo $ordmaster['invoice_number'];?></p>
<p style="float:left; font-weight:bold;">Date : <?php echo getDateFormat($ordmaster['order_received_date'],1);?></p>
  </div>
  <div>
          <?php if($formPage==''){?>
          <img src="<?php echo theme_url(); ?>images/print-icon.png" alt="" style="vertical-align:middle; margin-right:5px;" /><a href="javascript:void(0);" onclick="print();" style="color:#1e1e1e; text-decoration:none;  font-size:12px; "><span >Print Page</span></a><?php }?></div>

    </div>
    </div>

最佳答案

尝试用 href 替换内容

$('#show_dialog').click(function() {

    $.fancybox({
        type: 'inline',
        href: '#img_url'
    });
});

还有另一种方法可以做到这一点

您的 a 标签 html 将是

<td class="center" style="border:#f4f4f4 1px solid; padding:10px"><a href="#img_url" id="show_dialog" >Show Image</a></td>
        </tr>

然后像这样调用你的 fancybox

$("a#show_dialog").fancybox({});

关于javascript - 如何通过 jquery fancy box 在框中打开图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823143/

相关文章:

javascript - 如何防止 onInput 在动态组件初始化期间触发?

javascript - 多维数组 Javascript

javascript - 下拉子菜单选择

javascript - 在jquery php中解析json数组

javascript - Jquery 事件处理程序仅适用于匿名函数?

javascript - 如果我在 div 中单击,如何使用 javascript/jquery 检查?(我在这里做了研究——我需要更好的)

javascript - 使用 jquery 'this' 压缩代码

javascript - JavaScript 中的数组

php - 使用 PHP 从 XML 表中提取 NHL 排名

php - 如何在sql中的字符串值中获取数字是否存在