CGI html標籤學習

 1.上次講過了CGI的編程風格,今天來講一下,怎麼創建HTML的一些標籤。

首先要組存一個完整的HMTL頁面,標籤是少不了的。

 

  1. #!/usr/bin/perl -w 
  2. use CGI qw(:standard); 
  3.  
  4. print 
  5.     header(-charset=>'utf8'), 
  6.       start_html(-title=>'Test page'), 
  7.         h1('Simple Test'), 
  8.         ul(li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy'])), 
  9.         ol({compact=>undef},li('one'),li('two'),li('three')), 
  10.         table({-border=>undef},caption('When Should You Eat Your Vegetables?'), 
  11.         Tr({-align=>'CENTER',-valign=>'TOP'},[ 
  12.         th(['Vegetable''Breakfast','Lunch','Dinner']), 
  13.         td(['Tomatoes' , 'no''yes''yes']), 
  14.         td(['Broccoli' , 'no''no''yes']), 
  15.         td(['Onions' , 'yes','yes''yes'])])),p, 
  16.         checkbox_group(-name=>'words',-values=>['eenie','meenie','minie','moe'],-defaults=>['eenie']),p, 
  17.         "What's your favorite color?"
  18.         popup_menu(-name=>'color',-values=>['red','green','blue','chartreuse']),p, 
  19.         textfield(-name=>'field_name',-default=>'starting value',-override=>1,-size=>50,-maxlength=>80),p, 
  20.         filefield(-name=>'uploaded_file',-default=>'starting value',-size=>50,-maxlength=>80),p, 
  21.         scrolling_list('list_name',['eenie','meenie','minie','moe'],['eenie','moe'],5,'true',{'moe'=>{'class'=>'red'}}),p, 
  22.         radio_group(-name=>'group_name',-values=>['man','woman','child','girls'],-rows=>'2',-columns=>'2'),p, 
  23.         image_button(-name=>'button_name',-src=>'../icons/up.png',-align=>'MIDDLE'),p 
  24.         button(-name=>'button_name',-value=>'user visible label',-onClick=>"response()"),p, 
  25.         img{src=>'../icons/upload/RHEL6_720x60.png',align=>'LEFT'}; 
  26.       end_html; 

這裏講了HTML的一些標籤,上面用的是function-oriented style來創建的,下面用object-oriented style 來創建這些HTML標籤。

 

  1. #!/usr/bin/perl -w 
  2. use CGI; 
  3. use strict; 
  4.  
  5. my $q = new CGI; 
  6.  
  7. print 
  8.      $q->header(-charset=>'utf8'), 
  9.         $q->start_html(-title=>'Test Page'), 
  10.             $q->h1('Simple Test'), 
  11.             $q->ul($q->li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy'])), 
  12.             $q->ol({compact=>'undef'},$q->li('one'),$q->li('two'),$q->li('three')), 
  13.             "When Should You Eat Your Vegetables?"
  14.             $q->start_table({-border=>undef}), 
  15.                 $q->start_Tr({-align=>'CENTER',-valign=>'TOP'}), 
  16.                     $q->start_th, 
  17.                     "Vegetable"
  18.                     $q->end_th, 
  19.                     $q->start_th, 
  20.                     "Breakfast"
  21.                     $q->end_th, 
  22.                     $q->start_th, 
  23.                     "Lunch"
  24.                     $q->end_th, 
  25.                     $q->start_th, 
  26.                     "Dinner"
  27.                     $q->end_th, 
  28.                 $q->end_Tr, 
  29.                 $q->start_Tr, 
  30.                     $q->start_td, 
  31.                     "Tomatoes"
  32.                     $q->end_td, 
  33.                     $q->start_td, 
  34.                     "no"
  35.                     $q->end_td, 
  36.                     $q->start_td, 
  37.                     "yes"
  38.                     $q->end_td, 
  39.                     $q->start_td, 
  40.                     "yes"
  41.                     $q->end_td, 
  42.                 $q->end_Tr, 
  43.                 $q->start_Tr, 
  44.                     $q->start_td, 
  45.                     "Broccoli"
  46.                     $q->end_td, 
  47.                     $q->start_td, 
  48.                     "no"
  49.                     $q->end_td, 
  50.                     $q->start_td, 
  51.                     "no"
  52.                     $q->end_td, 
  53.                     $q->start_td, 
  54.                     "yes"
  55.                     $q->end_td, 
  56.                 $q->end_Tr, 
  57.                 $q->start_Tr, 
  58.                     $q->start_td, 
  59.                     "Onions"
  60.                     $q->end_td, 
  61.                     $q->start_td, 
  62.                     "yes"
  63.                     $q->end_td, 
  64.                     $q->start_td, 
  65.                     "yes"
  66.                     $q->end_td, 
  67.                     $q->start_td, 
  68.                     "yes"
  69.                     $q->end_td, 
  70.                 $q->end_Tr, 
  71.             $q->end_table,$q->p, 
  72.         $q->checkbox_group(-name=>'words',-values=>['eenie','meenie','minie','moe'],-defaults=>['eenie']),$q->p, 
  73.         "What's your favorite color?",$q->popup_menu(-name=>'color',-values=>['red','green','blue','chartreuse']),$q->p, 
  74.         $q->textfield(-name=>'field_name',-default=>'starting value',-override=>1,-size=>50,-maxlength=>80),$q->p, 
  75.         $q->filefield(-name=>'uploaded_file',-default=>'starting value',-size=>50,-maxlength=>80),$q->p, 
  76.         $q->scrolling_list('list_name',['eenie','meenie','minie','moe'],['eenie','moe'],5,'true',{'moe'=>{'class'=>'red'}}),$q->p, 
  77.         $q->radio_group(-name=>'group_name',-values=>['man','woman','child','girls'],-rows=>'2',-columns=>'2'),$q->p, 
  78.         $q->image_button(-name=>'button_name',-src=>'../icons/up.png',-align=>'MIDDLE'),$q->p, 
  79.         $q->button(-name=>'button_name',-value=>'user visible label',-onClick=>"response()"),$q->p, 
  80.         $q->img({-src=>'../icons/upload/RHEL6_720x60.png',-align=>'LEFT'}), 
  81.         $q->end_html; 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章