2013-04-09 94 views
1

我在PHP這個功能,它進來一個項目,我的工作:如何用JavaScript填充IMG src?

foreach ($reports["included_reports"] as $index => $report_name) { 
    if (! in_array($report_name, $reports["excluded_reports"])) { 
     $optional_reports .= 
     "<div class=\"large-12 columns\"> 
     <div class=\"panel\"> 
      <a href=\"./graph_all_periods.php?$graph_args&amp;g=". $report_name ."&amp;height=???&amp;width=???\"> 
      <img BORDER=0 style=\"padding:2px;\" $additional_cluster_img_html_args title=\"$cluster_url\" SRC=\"./graph.php?$graph_args&amp;g=". $report_name ."&amp;height=???&amp;width=???\" > 
      </a> 
     </div> 
     </div>"; 
    } 
} 

我想調整圖像大小,以填補我的格,但我不能使用width:100%是因爲我有通知widthheight到PHP。但是PHP首先執行,我也不知道用戶監視器的分辨率。在Google中搜索我發現了I only can know the user monitor resolution via JavaScipt。 所以我想知道是否有可能做一些我可以知道用戶監控並通知我的widthheigh參數img標籤。

+0

確實高度= ???&寬度= ???必須填寫?否則,您可以使用jquery調整圖像大小 – 2013-04-09 13:57:15

+0

@StephanusYanaputra,問題是'img'是由'graph.php'生成的,我必須通知大小。 – 2013-04-09 13:58:53

+0

@ValterHenrique雖然你需要在graph.php中指定大小,但你仍然不需要在這裏設置img標籤 – MrGlass 2013-04-09 14:01:00

回答

1

最佳方式,以確保圖像將總是填充一個div將其設置爲背景圖像,並使用CSS背景尺寸伸展它

0

在你的js中,爲用戶顯示器嘗試window.screen.widthwindow.screen.height。對於圖片尺寸,您可以在css中使用100%,然後使用0123x在px中獲得js的高度和寬度。