gpt4 book ai didi

javascript - Perl CGI,多个表单和多个提交按钮,在同一页面上执行操作

转载 作者:行者123 更新时间:2023-12-02 14:20:45 24 4
gpt4 key购买 nike

假设我有多个按钮并且“action=”也在同一页面上,如何指定点击 Perl CGI HTML 输出上的多个按钮之一执行哪个操作?

这是 html 输出,按钮(处理事件和重复记录)工作正常,但“导入信息”(我正在尝试实现)调用“处理事件”

这是java脚本代码:

<script type="text/javascript" src="$HostedSiteURL/$ScriptDirectory/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
\$(document).ready(function() {

\$('#importFromCAD').click(function () {
\$('#importNav').val('');
return true;

\$('#process-activity').click(function () {
\$('#DupNav').val('');
return true;
});

以及 Perl CGI HTML 代码:

sub NewRightSide
{
print " <div style=\"z-index:86;\" class=\"group-shell\">";
print " <table>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"importFromCAD\" type=\"submit\" value=\"Import Info\"></td></tr>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"process-activity\" type=\"submit\" value=\"Process Activity\"></td></tr>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"duplicate-record\" type=\"submit\" value=\"Duplicate Record\"></td></tr>\n";

picture of button layout

我相信这是被调用的形式:

 print "<form name=\"form\" accept-charset=\"utf-8\" method=\"post\"    action=\"A_CT_DIAL8.pl\">\n";
if ($Nav eq "" || $Nav eq "None") {$Nav="NewEntry";}
print "<input type=\"hidden\" name=\"s\" value=\"$escape_session\" />\n";
print "<input type=\"hidden\" name=\"nav\" value=\"DIAL\" id=\"nav\">\n";
print "<input type=\"hidden\" name=\"Nav\" value=\"$Nav\" id=\"Nav\">\n";
print "<input type=\"hidden\" name=\"SubNav\" value=\"$SubNav\">\n";
print "<input type=\"hidden\" name=\"DupNav\" value=\"\" id=\"DupNav\">\n";
print "<input type=\"hidden\" name=\"nav_tab\" value=\"\" id=\"nav_tab\">\n";
print "<input type=\"hidden\" name=\"Report\" value=\"\" id=\"Report\">\n";
print "<input type=\"hidden\" name=\"TransLimit\" value=\"$TransLimit\">\n";

这是名为“DupNav”的 Perl 子例程,我不确定它在表单功能中发挥的作用。这是第二个 .click(function ()) 类的子例程吗?

  if ($DupNav eq "")
{
$Nav = ""; $KeyField = ""; # $CAD = "";
$In = ""; $Out = ""; $Via = "";
$Status = ""; $Device = ""; $ActivitySubject = "";
$Memo = ""; $currenttime = ""; $NormalMemo = "";
$CheckNewMemo = ""; $PostMile = "";
}
else
{
$CheckRadio="No";
if ($DupWarn ne "Off")
{
$JavaWarn=$JavaWarn."Duplicated Last Entry. ";
$Warn=$Warn." [ Duplicated Last Entry ]";
$SubNav="Go";
}
else
{
$JavaWarn=$JavaWarn."Use the Duplicate Record button to pre fill the next entry with the same information as the last entry. ";
$Warn=$OldWarn." [ Use the Duplicate Record button to pre fill the next entry with the same information as the last entry ]";
}
}
if ($Device == 0) {$Device="";}
$currentdate = "";


$SplitMemo=$CheckNewMemo;
@GetEntries=split(":DOSEP:", $SplitMemo);
$EntryCount=@GetEntries;
$Memo=$GetEntries[0];

$b=1;
while ($b < $EntryCount)
{
$SplitExtras=$GetEntries[$b];
@GetExtras=split(":", $SplitExtras);
$ExtraListName=$GetExtras[0];
$ExtraListInfo=$GetExtras[1];
if ($ExtraListName eq "PostMile") {$PostMile=$ExtraListInfo; $DisablePostMileSection="No";}else{$Extra_Information{$ExtraListName}="$ExtraLis tInfo";}
$b++;
}

}

我知道这很长,我真的很感激能得到的任何反馈。我可以根据需要发布其他信息。再次感谢您。

最佳答案

为所有submit按钮赋予唯一的name属性,提交数据将只有一个submit参数,即被点击的参数。通过检查其名称来找出它是什么并进行相应的处理。下面给出了一些示例代码。

客户端:

<form method="POST" action="/act">
<input name="formid" value="1" type="hidden">
<input class="delete" value="D" name="delete" type="submit">
<input class="edit" value="E" name="edit" type="submit">
</form>

服务器端:

if ( defined param('edit')) {
# perhaps identify form by some checking for some hidden element
# process the data for edit
}
elsif ( defined param('delete') ) {
# perhaps identify form and process the data for delete
}

关于javascript - Perl CGI,多个表单和多个提交按钮,在同一页面上执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38663861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com