0

我正在尝试创建一个打开任何 URL 的模式,其中a标签具有特定的类。

在 colorbox 文档中,它有一个例子:

// ColorBox can accept a function in place of a static value:
$("a.gallery").colorbox({rel: 'gal', title: function(){
  var url = $(this).attr('href');
  return '<a href="' + url + '" target="_blank">Open In New Window</a>';
}});

我的 HTML 结构是:

" 类="模态" rel="gal">

        <h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>

        <div class="entry">
            <?php the_excerpt(); ?>
        </div>

</div>

我的JS是:

jQuery(".modal").colorbox({rel: 'gal', title: function(){
  var url = jQuery(this).attr('href');
  return '<a href="' + url + '" target="_blank">Open In New Window</a>';
}});

但这只是没有触发 - 我没有收到任何控制台 JS 错误 - 任何人都可以看到这里有什么问题吗?

4

3 回答 3

0

您正在元素上使用该colorbox()方法<div>,这些元素对于该方法不是有效的元素。此方法只能用于<a>元素。

于 2013-03-15T17:15:57.597 回答
0

完全误解了该功能 - 如果您尝试执行我在开篇文章中概述的内容,请使用 iframe 功能。

例如

jQuery(function () {
    jQuery(".modal").colorbox({iframe:true, innerWidth:425, innerHeight:344});    
})
于 2013-03-15T17:16:14.437 回答
0

parent.$.colorbox.resize({ 宽度: 460, 高度: 130 });

于 2013-03-15T18:11:42.703 回答