html中如何获取表单的数据?

代码如下:
<form id="form1" name="form1" method="post" action="index.php
src=325&item=iframe&action=save&t=&lc=2" onsubmit="return check();" style="width:433px;height:301px">
<table width="433" height="301" cellpadding="0" cellspacing="0" style="background-image:url(images/sub_mi_expo_05.jpg); width:433px; height:301px;">
<tr>
<td height="70"></td>
</tr>
<tr>
<td width="105" align="right" height="40" class="font_color">您的姓名:</td>
<td align="left" width="102" style="width:102px; overflow:hidden;"><input type="text" id="name" name="name1" maxlength="8"/></td>
<td align="right" width="50" class="font_color" style="width:50px; overflow:hidden;">手机:</td>
<td align="left" width="176"><input type="text" id="phone" name="phone1" maxlength="11"/></td>
</tr>
<tr>
<td width="105" align="right" height="45" class="font_color">收票地址:</td>
<td colspan="3"><input type="text" id="address" name="address" maxlength="100" /></td>
</tr>
<tr>
<td width="105" align="right" height="35" class="font_color">快递时间:</td>
<td colspan="3"><input type="radio" name="express" value="3" checked="checked"/>任何一天 <input type="radio" name="express" value="1"/>工作日 <input type="radio" name="express" value="2"/>双休日 </td>
</tr>
<tr>
<td height="55"></td>
<td colspan="3"><p style="width:154px; text-align:center; float:left; height:37px; font-size:12px; color:#FF6666; overflow:hidden; line-height:34px; background-image:url(images/new_cdbm_12.jpg); background-repeat:no-repeat;">已有<font style="font-size:22px; color:#FF0000; font-family:Arial;"></font>人报名</p>
<p style="width:127px; height:37px;float:left;"><input type="submit" value="" id="order_sh" style=" cursor:pointer;background-image:url(images/TIJ_EXPO_NEW_06.jpg); border:0;width:127px; height:37px;" /></p></td>
</tr>
</table>
麻烦大神能写代码的写一下代码!谢谢。

html中获取表单数据的的方法一般有两种,一个是使用form表单的action属性将表单的数据提交给后台,另外一种就是使用JavaScript方法获取表单的数据,然后通过ajax传送给后台。

工具原料:编辑器、浏览器

一、使用表单的方法提交数据

1、利用form表单的action属性来获取表单的数据并提交,代码如下:

<form action="form_action.php" method="get">
  <p>First name: <input type="text" name="fname" /></p>
  <p>Last name: <input type="text" name="lname" /></p>
  <input type="submit" value="Submit" />
</form>

2、以上代码中method指定提交数据的方法为get,action的值是表单数据提交的地址。

二、使用JavaScript方法来获取表单的数据的方法

1、可以使用JavaScript的选择器选择表单的元素并获取其输入的数据,代码如下:

<form action="form_action.php" method="get">
   <p>First name: <input id="bt1" type="text" name="fname" /></p>
   <p>Last name: <input id="bt2" type="text" name="lname" /></p>
   <input type="submit" value="Submit" />
  </form>
   <script>
   console.log($('#bt1').val())
   console.log($('#bt2').val());
   </script>

2、其中$('#bt1').val()就是获取input输入内容的值

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-31

document.getElementById('b').value
或者
form1.a.value

在页面间传递,<script>function goURL(theform){  var gourl = "456.html"; 

gourl +="?p="+theform.username.value+"|"+theform.email.value; theform.action = gourl; return true;

}</script><form method=get onsubnit="return goURL(this);

"><input type=text name=username><input type=text name=email><input type=button value=提交 

onclick="goURL(this.form)"></form> 在456.html页面用脚本叫URL问号后面的值分割后,再用"|"分割就得到username和email<script>function init(){   var url= document.location.href.split("?") 

temp =url.split("|");  

alert("UserName="+temp[0]+"\n"+"Email="+temp[1]); }</script><body onload=init()> </body>

本回答被网友采纳
第2个回答  2013-07-17
java中可以在后台通过request.getParameter(name);来获得;
如:<input type="text" id="name" name="name1" maxlength="8"/>
后台则根据input标签中name的名字来获得:
String name=request.getParameter("name1");
对于php原理也差不多,request中应该有对应方法去获得。
第3个回答  2013-07-18
$name = $_POST["name1"] ;

就可以取到数据了。
这个代码可以运行下去吗?你的路径存在问题,传的数据可能到不了你要的运行文件。追问

只需获取 您的姓名:手机:收票地址:就可以了值存在文本里

本回答被提问者采纳
第4个回答  2013-07-24
form标签要回来啊,它们是成对的标签呢