2011-09-22 45 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' 
     }); 
    }); 
});