开发者

Can cgi's start_html() method have multiple -script attributes?

I think the question is pretty self explanitory, but I'm using 开发者_如何转开发perl to generate a webpage. Starts off using:

$cgi->start_html(-title=>'myPage',-style=>{-src=>'style.css'},  -script=>{-type=>'JAVASCRIPT', -src=>'custom.js'}, );

List item

But what if I want to have multiple scripts in the the header? Or Multiple CSS style sheets?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="custom.js"></script>
<link rel="stylesheet" href="css/basic.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />


Use anonymous array:

$cgi->start_html(
  -title=>'myPage',
  -style=>[{-src=>'style.css'},{-src=>'basic.css'}],
  -script=>[{-type=>'JAVASCRIPT', -src=>'custom.js'},{-type=>'JAVASCRIPT', -src=>'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'}],
);


Of course. When you think more than one, think array. When you think passing arrays as arguments, think array ref.

use warnings;
use strict;
use CGI qw(:standard);

print start_html(-title => "myPage",
                 -style => [ {-src=>"style.css"},
                             {-src=>"basic.css"}, ],
                 -script => [ {-type=>"text/javascript",
                               -src=>"custom.js"},
                              {-type=>"text/javascript",
                               -src=>"ohai.js"}, ], );

__END__

…snip…
<title>myPage</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="basic.css" />
<script src="custom.js" type="text/javascript"></script>
<script src="ohai.js" type="text/javascript"></script>
…snip…
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜