【问题标题】:load content from page.. by the href of a class... inside a modal从页面加载内容..通过类的href...在模态中
【发布时间】:2012-08-04 14:36:25
【问题描述】:

尝试执行以下操作: 我的页面有很多带有 's 的 div 来打开模态框(颜色框)。这些链接打开的页面有一个 id="mainColumn"。内容只需要从这个 id 加载。

我有这个:

<div>                       
<a href="includes/page_1.html" class="modal"></a>
</div>

<div>                       
<a href="includes/page_2.html" class="modal"></a>
</div>

<div>                       
<a href="includes/page_3.html" class="modal"></a>
</div>


 $(".modal").colorbox({
    width:900,
    href: $(".modal").attr('href') + " #mainColumn"
    });

效果很好...除了 al 的 href 更改为第一个...

所以 包含/page_3.html 更改为包含/page_1.html 或者换句话说:所有的模态框都显示相同的内容......

任何帮助将不胜感激,谢谢

【问题讨论】:

    标签: jquery modal-dialog colorbox html-content-extraction


    【解决方案1】:

    使用$(this) 获取当前(点击)一个

    $(".modal").colorbox({
        width:900,
        href: $(this).attr('href') + " #mainColumn"
    });
    

    【讨论】:

    • 你需要控制执行上下文。
    【解决方案2】:
    $(".pop").each(function() {
      var el = $(this);
      el.colorbox({
        href: el.attr('href') + " #mainColumn"
      });
    });
    

    【讨论】:

      【解决方案3】:

      你可以这样做:

      $(".modal").colorbox({
          width:900,
          href: function(){ return $(this).attr('href') + " #mainColumn"; }
      });
      

      或者这个:

      $(".modal").each(function(){
          $(this).colorbox({
              width:900,
              href: $(this).attr('href') + " #mainColumn"
          });
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多