2011-09-22 22 views
0

如何检索我的标签上的宽度设置(例如在REL属性中)并将其传递给我的jQuery fancybox函数,以便我可以指定其宽度?这是我的(非常标准)的fancybox声明:从链接rel属性设置fancybox宽度

 <script type="text/javascript"> 
     $(document).ready(function() { 
      //TODO - pass width/height value from link somehow 
      $("a.popup").fancybox({ 
       'autoScale': false, 
       'height': 500, 
       'transitionIn': 'elastic', 
       'transitionOut': 'elastic', 
       'type': 'iframe' 
      }); 
     }); 
    </script> 

回答

1

你真的不应该对超载这个rel属性,这不是什么它是。

但是,代码可能看起来像......

$(document).ready(function() { 
    $("a.popup").each(function() { 
     var width = $(this).attr('rel'); 

     $(this).fancybox({ 
      'autoScale': false, 
      'width': width, 
      'height': 500, 
      'transitionIn': 'elastic', 
      'transitionOut': 'elastic', 
      'type': 'iframe' 
     }); 
    }); 
});