html——表单(1)

来源:互联网 发布:网络安全教育开题报告 编辑:程序博客网 时间:2024/04/29 03:40

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

语法:

<form   method="传送方式"   action="服务器文件">

讲解:

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

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

3.method : 数据传送的方式(get/post)。

注意:

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


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form method="post" action="save.php">
 <label for="username">用户名:</label>
    <input type="text" name="username"/>
    <label for="pass">密码:</label>
    <input type="password" name="pass"/>
    <input type="submit" value="确定"  name="submit" />
</form>
</body>
</html>


1、type:

   当type="text"时,输入框为文本输入框;

   当type="password"时, 输入框为密码输入框。

2、name:为文本框命名,以备后台程序ASP 、PHP使用。

3、value:为文本输入框设置默认值。(一般起到提示作用)


    <input type="text" name="username" value="小明"/>
    <label for="pass">密码:</label>
    <input type="password" name="pass" value="123456"/>


当用户输入有错误需要重新输入的时候,可以使用重置功能:

 <input type="reset" value="重置" name="cz"/>

0 0
原创粉丝点击