HTML学习(4)表单form向服务器提交数据

HTML中表单用于向服务器提交信息,之前写动态页面的时候就已经用过,代码内容如下:

    <form action="/input", method="post"> 
        {% csrf_token %}   <!--django有跨站请求保护机制要求必须添加此行 -->
        用户名:<input type="text" name="username"/><br/>
        密 码:<input type="password" name="password"/><br/>
        <input type="submit" value="提交">
    </form>

action属性值为url,规定当提交表单时向何处发送表单数据
method属性的值为get或者post,规定用于发送 form-data 的 HTTP 方法
{% csrf_token %} django有跨站请求保护机制要求必须添加此行,原因未知,先用着再说

标签用于换行
标签用于用于输入数据,输入字段可以有多种形式(文本、复选框、按钮等)

标签

1、输入文本

<html>
<body>

<form action="/example/html/form_action.asp" method="get">
<input type="text" id="user-name" required 
placeholder="姓名" name="name">
<input type="submit" value="Submit" />
</form>

</body>
</html>

type 属性规定 input 元素的类型
required 属性表示必填字段
placeholder 输入提示信息,显示在文本框内
name 属性输入的元素名称

以上代码显示结果为:
在这里插入图片描述

2、单选按钮radio

<form action="/example" method="get">
  <input type="radio" name="sex" value="male" /> 男<br />
  <input type="radio" name="sex" value="female" /> 女<br />
  <input type="submit" value="提交" />
</form>

运行结果
在这里插入图片描述

参考资料:
http://www.w3school.com.cn/tags/att_input_type.asp
http://www.w3school.com.cn/tags/tag_form.asp
http://www.runoob.com/tags/tag-form.html

猜你喜欢

转载自blog.csdn.net/liying15/article/details/86658182
今日推荐