<!DOCTYPE html> <html> <body> <form> First name: <input type="text" name="firstname" /><br /> Last name: <input type="text" name="lastname" /><br /> <input type="submit" value="Submit" /> </form> </body> </html>
当我点击该按钮时,为了有一些“动作”,我需要有什么?
解决方法
完成环境设置后,您可以开始使用Webforms.直接从文章:Processing form data with PHP:
For this example you will need to create two pages. On the first page
we will create a simple HTML form to collect some data. Here is an
example:06000
This page will
send the Name and Age data to the page process.PHP. Now lets create process.PHP to use
the data from the HTML form we made:
<?PHP print "Your name is ". $Name; print "<br />"; print "You are ". $Age . " years old"; print "<br />"; $old = 25 + $Age; print "In 25 years you will be " . $old . " years old"; ?>
As you
may be aware,if you leave out the method=”post” part of the form,the
URL with show the data. For example if your name is Bill Jones and you
are 35 years old,our process.PHP page will display as
07002 If you want,
you can manually change the URL in this way and the output will change
accordingly.
其他JavaScript示例
这个单一文件示例从您的问题中获取html,并将表单的onSubmit事件与一个JavaScript函数相关联,该函数会拉取2个文本框的值,并将其显示在警报框中.
注意:document.getElementById(“fname”).value获取ID标签等于fname的对象,然后提取它的值 – 在这种情况下,它是“名字”文本框中的文本.
<html> <head> <script type="text/javascript"> function ExampleJS(){ var jFirst = document.getElementById("fname").value; var jLast = document.getElementById("lname").value; alert("Your name is: " + jFirst + " " + jLast); } </script> </head> <body> <FORM NAME="myform" onSubmit="JavaScript:ExampleJS()"> First name: <input type="text" id="fname" name="firstname" /><br /> Last name: <input type="text" id="lname" name="lastname" /><br /> <input name="Submit" type="submit" value="Update" /> </FORM> </body> </html>