JavaScript文本不提交表单
我正在处理我的第一个Web应用程序,并尝试使用JavaScript通过单击文本来提交表单。当我点击文字时,什么都没有发生。现在应该打开一个简单的网页。我知道如何使用html处理表单,但是当我尝试使用JavaScript时,什么也没有发生。我正在使用unix,并且我已经配置了我的服务器和chmod 755 cgi文件。我不是这不是一个服务器错误,因为我之前已经执行了它的CGI文件。我正在学习本教程:
http://www.thesitewizard.com/archive/textsubmit .shtml
I am working on my first web application and I am trying to use javascript to submit a form by clicking on text. When I click on the text nothing happens. It should just open to a simple webpage for now. I know how to process forms with html, but when I try and use javascript nothing happens. I am using unix and i have already configured my server and chmod 755 the cgi file. I not it is not a server error as I have executed cgi files on it before. I am following this tutorial: http://www.thesitewizard.com/archive/textsubmit.shtml
以下是我测试的html:
Here is my test html:
<html>
<head>
<title>EDVT Report Generator</title>
<style>
h1 {
text-align: center;
}
<script language="JavaScript" type="text/javascript">
function getsupport ( selectedtype )
{
document.supportform.supporttype.value = selectedtype ;
document.supportform.submit() ;
}
</script>
</style>
</head>
<body>
<h1 id = "title">Test</h1>
<form name="supportform" method="post" action="/cgi-bin/hello.py">
<input type="hidden" name="supporttype" />
<a href="javascript:getsupport('Paid')" onclick = "getsupport('Paid')">Paid Support</a> or
<a href="javascript:getsupport('Free')" onclick = "getsupport('Free')">Free Support</a>
</form>
</body>
</html>
这里是cgi文件:
#!/usr/bin/python
import cgitb, cgi
cgitb.enable()
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
由于我没有太多的JavaScript经验,我完全丧失了什么是错误的。任何帮助感激!
I am at a complete loss with what is wrong as I do not have much experience with javascript. Any help is appreciated!
不能嵌套< script>
元素放入< style>
中,唯一允许的内容是CSS。见例如 MDN文档。
You cannot nest a <script>
element inside <style>
, the only allowed content is CSS. See e.g. the MDN docs.
将< script>
移至< head>
或 < body>
:
<html>
<head>
<title>EDVT Report Generator</title>
<style>
h1 {
text-align: center;
}
</style>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function getsupport ( selectedtype )
{
document.supportform.supporttype.value = selectedtype ;
document.supportform.submit() ;
}
</script>
<h1 id = "title">Test</h1>
<form name="supportform" method="post" action="/cgi-bin/hello.py">
<input type="hidden" name="supporttype" />
<a href="javascript:getsupport('Paid')" onclick = "getsupport('Paid')">Paid Support</a> or
<a href="javascript:getsupport('Free')" onclick = "getsupport('Free')">Free Support</a>
</form>
</body>
</html>