如何更改 CGI 程序中的行跨度属性?
我正在编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
顺便说一句,我建议您考虑使用一些模板处理系统,例如Template Toolkit。
Try this:
BTW, I would suggest you to consider using some template processing system, e.g. Template Toolkit.