我有一个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" />
Run Code Online (Sandbox Code Playgroud)
并且,在您的脚本中:
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
}
Run Code Online (Sandbox Code Playgroud)