如何更改 CGI 程序中的行跨度属性?

发布于 2024-08-22 02:14:02 字数 886 浏览 2 评论 0原文

我正在编写一个 CGI 脚本来处理表单数据,它应该在表中打印输入的名称及其值。当我有一个或多个具有相同名称的值时,该名称应跨行以容纳与该名称对应的所有值。例如,如果我的名称为“color”,其值为“red”、“green”、“blue”,则颜色应跨越表中的 3 行。我的问题是,如何更改脚本中的 rowspan 属性以适应这种情况:

#!/usr/bin/perl --
use strict;
use CGI;

print <<HTTP;
Status: 200 OK
Content-Type: text/html

HTTP

print <<HTML; 
<html>
    <head>
        <title>Parameters<title>
    <head>

    <body>
     <table border="1" cellpadding="5" cellspacing="1">
     <tr>

     <th>Name</th>
     <th>Value</th>

     </tr>

HTML

 my $query = new CGI;

 my($name, $value);

 foreach $name ( $query->param)
 {
    print "<tr>";
    print "<td>$name</td>";

    foreach $value($query->param($name))
    {
        print "<td>$value</td>";
        print "</tr>";
    }



}

I am writing a CGI script that will process form data, and it should print the name of the input, along with its value, in a table. When I have one or more values with the same name, the name should span rows to accommodate all values that correspond to that name. For example, if I have a name "color" with its values at "red", "green", "blue", then color should span 3 rows in my table. My question is, how would i change the rowspan attribute in my script to accommodate this:

#!/usr/bin/perl --
use strict;
use CGI;

print <<HTTP;
Status: 200 OK
Content-Type: text/html

HTTP

print <<HTML; 
<html>
    <head>
        <title>Parameters<title>
    <head>

    <body>
     <table border="1" cellpadding="5" cellspacing="1">
     <tr>

     <th>Name</th>
     <th>Value</th>

     </tr>

HTML

 my $query = new CGI;

 my($name, $value);

 foreach $name ( $query->param)
 {
    print "<tr>";
    print "<td>$name</td>";

    foreach $value($query->param($name))
    {
        print "<td>$value</td>";
        print "</tr>";
    }



}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_失温 2024-08-29 02:14:02

试试这个:

my $query = new CGI;
my($name, $value);

foreach $name ($query->param) {
    my @values = $query->param($name);
    my $count  = @values;

    print "<tr>";
    print "<td rowspan='$count'>$name</td>";
    print "<td>".shift(@values)."</td>";
    print "</tr>";    

    foreach $value (@values) {   
        print "<tr>";
        print "<td>$value</td>";
        print "</tr>";
    }
}

顺便说一句,我建议您考虑使用一些模板处理系统,例如Template Toolkit

Try this:

my $query = new CGI;
my($name, $value);

foreach $name ($query->param) {
    my @values = $query->param($name);
    my $count  = @values;

    print "<tr>";
    print "<td rowspan='$count'>$name</td>";
    print "<td>".shift(@values)."</td>";
    print "</tr>";    

    foreach $value (@values) {   
        print "<tr>";
        print "<td>$value</td>";
        print "</tr>";
    }
}

BTW, I would suggest you to consider using some template processing system, e.g. Template Toolkit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文