我认为问题非常自我解释,但我使用perl来生成网页。开始使用:
$cgi->start_html(-title=>'myPage',-style=>{-src=>'style.css'}, -script=>{-type=>'JAVASCRIPT', -src=>'custom.js'}, );
列出项目
但是如果我想在标题中有多个脚本怎么办?或多个CSS样式表?
<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" />
答案 0 :(得分:5)
使用匿名数组:
$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'}],
);
答案 1 :(得分:3)
当然。当您认为多个时,请考虑数组。当您认为将数组作为参数传递时,请考虑数组引用。
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…