【发布时间】:2011-07-22 19:38:07
【问题描述】:
以下是我的代码。我所有的按钮功能都可以正常工作,但是如果我单击链接,则应记住服务器的值,并且应使用参数视图和子系统再次重新加载页面。
但是当我重新加载时,服务器的值是空的。
my $server = $q->param('server') ;
my $unit = $q->param('unit') ;
my $bfile = __FILE__ ;
$bfile = `basename $bfile` ;
chomp $bfile ;
print "<form name=\"form1\" action =\"/cgi-bin/$bfile\" onsubmit=\"javascript:onsubmitform(doc_press)\">";
print "<input type=\"hidden\" name=\"server\" id=\"server\">";
print "<input type=\"hidden\" name=\"unit\" id=\"unit\">";
print "\n\n<input type=submit name=view value=\"View\" onClick=\"doc_press=this.value\">";
print "<input type=submit name=save value=\"Save\" onClick=\"doc_press=this.value\">";
print $var{$a}."<a href=\"/cgi-bin/$bfile?view=5&SUBSYS=$subsys\" onClick=javascript:click_page(\"$_\")>CLICK</a>\n" ;
print <<"END_OF_SCRIPT";
<script type="text/javascript">
function onsubmitform(doc_press) {
if (doc_press == "View"){
document.getElementById('unit').value="$unit";
}
else if (doc_press == "Save") {
END_OF_SCRIPT
var x = "$user=$val";
document.cookie=x;
document.getElementById('unit').value="$unit";
}
if (document.getElementById('HTTP_TYPE').value == "post") {
document.form1.method='post';
}
else if(document.getElementById('HTTP_TYPE').value == "get") {
document.form1.method='get';
}
}
function click_page(server){
document.getElementById('server').value=server;
}
</script>
END
【问题讨论】:
-
javascript:不属于onsomething=""处理程序。它不是 URL 而是 JavaScript 代码!此外,如果您使用 XHTML,它的属性必须完全小写,即onclick -
此代码甚至无法编译,提供您的真实代码。代码中至少缺少 6 个声明。
-
您知道您的字符串中不需要所有这些 \" 对吗?使用 qq{} 和瞧: print qq{go }; 更好的是,使用模板系统(我喜欢 Text::Template 的简单性,但 Template Toolkit 也很受欢迎)
-
@daxim:我只是给你参考代码,这样你就可以理解我的问题。我的整个程序是保密的。所以我不能在这里提供..谢谢
-
@mirod:谢谢你。但我已经习惯了......所以如果我也改变它会让我感到困惑......
标签: javascript perl onclick href