在perl cgi中添加指向head的链接

时间:2013-04-07 09:03:56

标签: perl cgi

我是Perl的新手,我正在尝试在perl生成的html页面中包含一个CSS文件, 我怎么能用cgi做到这一点? 它应该是类似的东西 print $ cgi - > start_html(-link => {-href =>'/ styles / main.css',-rel =>'stylsheet', - type =>'text / css'});

这是完整的代码,

#!C:\Dwimperl\perl\bin\perl.exe
use CGI;
my $cgi = new CGI;

# ###----- GETTING THE SCRIPTS AND STYLES ------###
my $jquery = "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";

# ###----- PRINTING THE PAGE -----###
print   $cgi -> header;
print   $cgi -> start_html(
            -title => "TestTitle",
            -link => { -href => '/styles/main.css', -rel => 'stylsheet', -type => 'text/css'},
            -script=> [{-language => 'javascript',-src => $jquery},{-code => $jscript}],
        );
print   $cgi -> h1({-class=>"title",-align=>"center"},"Zero Testing");
print   $cgi -> start_div({-align=>"center"});
print   $cgi -> start_div({-align=>"center",-style=>"margin-bottom:35px;"});
print   $cgi -> a({-class=>"linkButton",-id=>"btn_Page",-href=>"Test.pl"},"Suites Page");
print   $cgi -> end_div;
print   $cgi -> start_form({-method=>"get",-id=>"dataForm"});
print   $cgi -> end_form;
print   $cgi -> end_div;
print   $cgi -> end_html();

由于

1 个答案:

答案 0 :(得分:1)

你可以这样写:

use CGI qw/:standard/;

# ...     

print $cgi->start_html(
   -title =>"TestTitle",
   -script=> [ {-language => 'javascript',-src => $jquery}, {-code => $jscript} ],
   -head => [
      Link( { -href => '/styles/main.css', -rel => 'stylsheet', -type => 'text/css'}),
    ]
);