我有一个 Perl CGI 程序,我在其中设计了一个 HTML 表单。 如果有人单击此表单中的按钮,则会执行此文件中的 CGI/Perl 子例程。 因为表单中有多个按钮,所以我将它们的类型设置为“按钮”,而不是“提交”。
这是一个书店网站,我有三个按钮,每个按钮对应一种书籍(例如,我的按钮是:“科幻小说”、“小说”和“诗歌”)。我必须使用按钮。单击每个按钮后,将显示该类型的书籍列表,用户可以选择书籍。我不应该使用 javascript:它应该由 CGI 控制。
最佳答案
它应该像你的表单一样简单:
<input type="submit" name="Button1" value="Button 1" />
<input type="submit" name="Button2" value="Button 2" />
<input type="submit" name="Button3" value="Button 3" />
并且,在您的脚本中:
if ($cgi->param('Button1')) {
# Button1 was clicked, do stuff...
} elsif ($cgi->param('Button2')) {
# Button2 was clicked, do something else...
} elsif ($cgi->param('Button3')) {
# Button3 was clicked, do whatever you want...
} else {
# No button clicked; show the form
}
关于perl - 当有人单击按钮时,如何使 CGI 程序运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2258309/