2011-04-20 108 views
1

我正在用模块CGI.pm写Perl/CGI脚本。我可以返回文本/ html,但不能在其中包含图像,它始终显示'alt'标记,我确信href链接。CGI.pm:包含图像?

这里是我的代码:

#!/usr/bin/perl -w 
use strict; 
use CGI; 

my $cgi = new CGI; 

print $cgi->header(-type=>'text/html'), 
     $cgi->start_html(-title=>'Test Page'), 
     $cgi->h1('Infos switch'), 
     "This is a test.", 
     $cgi->h1('Testing'), $cgi->hr, "\n", 
     $cgi->img(-src=>'http://www.perl.org/simages/lcamel.gif', 
       -alt=>'Powered by Perl'), "\n\n", 
     $cgi->end_html; 
exit; 

回答

5

首先,你没有得到的替代文字。你发送<img>-src http://www.perl.org/simages/lcamel.gif -alt Powered by Perl,所以图像甚至没有ALT文本。

img的第一个参数应该是属性的散列。其余部分被视为子元素。

$cgi->img({ 
    -src => 'http://www.perl.org/simages/lcamel.gif', 
    -alt => 'Powered by Perl', 
}) 

破折号是可选的,所以你也可以使用

$cgi->img({ 
    src => 'http://www.perl.org/simages/lcamel.gif', 
    alt => 'Powered by Perl', 
}) 
+1

非常感谢伙计,我可以显示图片:)我现在必须格式化我所有的图片在浏览器上创建我的开关... – eouti 2011-04-20 07:29:09

+0

@eouti - 请接受他的回答! – 2011-04-20 18:53:44

+0

好的srry伙计,我不知道投票社区,不知道我们必须投票。 – eouti 2011-04-21 12:54:34