- 论坛徽章:
- 5
|
how about this ?
生成 html
try:
perl script.pl > this.html
firefox this.html- #!/usr/bin/perl
- #my @data = (); # test for empty @data;
- my @data = 'A' .. 'Z';
- my $count = @data;
- my @pages = map { join "\n<br>\n", @$_ }
- map { [ splice @data, 0, 10 ] } 0 .. $count / 10;
- my ( %html, $key );
- while (<DATA>) {
- if (/^#\s(\w+)/) {
- $key = $1;
- }
- else { $html{$key} .= $_ }
- }
- if ( !$count ) {
- print @html{qw/head_begin head_end body_begin/};
- print "<br><br>检索失败<br><br>";
- print $html{html_end};
- exit;
- }
- print $html{head_begin}, "\n";
- print $html{script}, "\n";
- print $html{head_end}, "\n";
- print $html{body_begin}, "\n";
- print "<br>总共 $count 条结果,每页显示10条<br><br>\n";
- print $html{page_1}, "\n";
- for my $e ( 1 .. $#pages ) {
- my $d = $e + 1;
- my $H =
- "<td class=\"inactive\" id=\"cell$d\" onclick=\"showLayer(this,\'d$d\',$e);\">页$d</td>";
- print $H, "\n";
- }
- print $html{page_2}, "\n";
- print
- "<div id=\"d1\" class=\"layer\" style=\"display:block;background-color:#FFFFFF;\">\n$pages[0]</div>\n";
- for my $e ( 1 .. $#pages ) {
- my $d = $e + 1;
- my $H =
- "<div id=\"d$d\" class=\"layer\" style=\"display:none;\">\n$pages[$e]</div>\n";
- print $H, "\n";
- }
- print $html{html_end};
- # html from
- # http://karen.cngogo.org/read.php?fid=5&tid=46&fpage
- __DATA__
- # head_begin
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="content-type" content="text/html;charset=utf-8" />
- <title> 检索结果 </title>
-
- # script
- <style>
- .active {
- border: 1px solid #7D7D7D;
- border-bottom: none;
- width:70;
- cursor:pointer;
- }
- .inactive {
- border: none;
- border-bottom: 1px solid #7D7D7D;
- width:70;
- cursor:pointer;
- }
- .layer {
- border: 1px solid #7D7D7D;
- border-top: none;
- width:800;
- height:200;
- }
- </style>
- <script type="text/javascript">
- var currentLayer = "cell1";
- var currentDiv = "d1";
- var defaultColor = "#FFFFFF";
- function showLayer(obj, div){
- if(currentLayer!=obj.id) {
- showIt(currentLayer,currentDiv,false);
- currentLayer = obj.id;
- currentDiv = div;
- showIt(currentLayer,currentDiv,true);
- }
- }
- function showIt(o, d, mode){
- var obj = document.getElementById(o);
- var div = document.getElementById(d);
- obj.className = mode ? "active" : "inactive";
- div.style.display = mode ? "block" : "none";
- }
- </script>
- # head_end
- </head>
- # body_begin
- <body>
- # page_1
- <table border="0" cellspacing="0" cellpadding="5">
- <tr align="center">
- <td class="active" id="cell1" onclick="showLayer(this,'d1');">页1</td>
- # page_2
- <td style="border-bottom:1px solid #7D7D7D;"> </td>
- </tr>
- </table>
- # html_end
- </body>
- </html>
复制代码 |
|