UPUPD技术论坛

标题: 【HTML基础】-3.10-使用表单标签form,与用户交互 [打印本页]

作者: 洛尘    时间: 2015-10-16 11:41
标题: 【HTML基础】-3.10-使用表单标签form,与用户交互
网站怎样与用户进行交互?

答案是使用HTML表单(form)。表单是可以把浏览者输入的数据传送到服务器端,这样服务器端程序就可以处理表单传过来的数据。

语法:

<form>:<form>标签是成对出现的,以<form>开始,以</form>结束。


2.action:浏览者输入的数据被传送到的地方,比如一个php页面(save.php)。


3.method:数据传送的方式(get/post)。
  1. <form method="post"  action="save.php">
  2. <label for-"username">用户名:</label>
  3. <input type="text" name="username" />
  4. <label for="pass">密码:</label>
  5. <input type="password" name="pass" />
  6. </form>
复制代码



注意:

1.所有的表单控件(文本框,文本域,按钮,单选框,复选框等)都必须放在<form></form>标签之间(否则用户输入的信息可不会提交到服务器上哦!)。

2.method:post/get的区别,这一部分内容属于后端程序员考虑的问题。感兴趣的同学可以自行百度一下。

任务:

在下面的代码中加入代码:method="post" action="save.php"

  1. <html>
  2.                 <head>
  3.                 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  4.                 <title>表单标签</title>
  5.                 </head>
  6.                 <body>
  7.                 <form>
  8.                       <label for="username">用户名:</label>
  9.                       <input type="text"  name="username" id="username" value="" />
  10.                       <label for="pass">密码:</label>
  11.                       <input type="password"  name="pass" id="pass" value="" />   
  12.                       <input type="submit" value="确定"  name="submit" />
  13.                       <input type="reset" value="重置" name="reset" />
  14.                 </form>
  15.                 </body>
  16.                 </html>
复制代码







欢迎光临 UPUPD技术论坛 (http://bbs.upupd.com/) Powered by Discuz! X3.2