HTML & CSS 基本入门【8】表单
<h2 style="color: black; text-align: left; margin-bottom: 10px;">前面</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">前面<span style="color: black;">咱们</span><span style="color: black;">已然</span>熟悉了网页上<span style="color: black;">有些</span><span style="color: black;">平常</span>的元素,如在网页上<span style="color: black;">表示</span>一段文字、一张<span style="color: black;">照片</span>、一个列表、一张表格等等。这些东西都是事先编辑好<span style="color: black;">表示</span>在页面上只<span style="color: black;">供给</span>给用户看的,<span style="color: black;">实质</span>上,<span style="color: black;">咱们</span><span style="color: black;">能够</span>把<span style="color: black;">这般</span>的页面<span style="color: black;">叫作</span>之为静态页面。有“静”就有”动”,自然<span style="color: black;">亦</span>就有了动态页面,<span style="color: black;">所说</span>动态页面<span style="color: black;">便是</span>在页面上能<span style="color: black;">供给</span>与用户产生交互的元素,<span style="color: black;">例如</span>:我们想注册<span style="color: black;">作为</span>某个网站的会员,就要填写注册信息提交给网站后台;<span style="color: black;">咱们</span>在网上<span style="color: black;">发布</span>评论;<span style="color: black;">咱们</span>在网上填写<span style="color: black;">有些</span>调查问卷等等。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-6127acf9ea13b35156649f328fe226b4_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上图的163邮箱注册页面<span style="color: black;">便是</span>一个表单,在表单中有文本框、下拉列表、按钮等元素,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">经过</span>这些元素完成数据的输入。<span style="color: black;">那样</span>,输入的数据该<span style="color: black;">怎样</span>收集呢?这个就不是HTML所讨论的问题了,属于后台开发,<span style="color: black;">倘若</span>您感兴趣,<span style="color: black;">咱们</span>得另开一栏。<span style="color: black;">这儿</span><span style="color: black;">咱们</span>先<span style="color: black;">认识</span>一下表单上的<span style="color: black;">平常</span>元素。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">表单元素</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> <form> 标签:用于创建一个表单,表单里面<span style="color: black;">能够</span><span style="color: black;">包括</span>文本框、按钮、下拉列表等元素。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><input> 元素(输入元素):是表单里面最常用的元素,它有多种<span style="color: black;">区别</span>的类型(<span style="color: black;">例如</span>:单行文本框、<span style="color: black;">暗码</span>框、单选按钮、复选框等等),<span style="color: black;">能够</span><span style="color: black;">经过</span>【type】属性来设置。下表列出了<span style="color: black;">平常</span>的类型及说明。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-f90351b8deb56167688a2c193aaa0700_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">示例代码:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><!DOCTYPE html></span>
<span style="color: black;"><</span><span style="color: black;">html</span> <span style="color: black;">xmlns</span><span style="color: black;">=</span><span style="color: black;">"http://www.w3.org/1999/xhtml"</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">meta</span> <span style="color: black;">http-equiv</span><span style="color: black;">=</span><span style="color: black;">"Content-Type"</span> <span style="color: black;">content</span><span style="color: black;">=</span><span style="color: black;">"text/html; charset=utf-8"</span><span style="color: black;">/></span>
<span style="color: black;"><</span><span style="color: black;">title</span><span style="color: black;">></</span><span style="color: black;">title</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">form</span><span style="color: black;">></span><span style="color: black;"><!--定义一个表单,表单<span style="color: black;">起始</span>--></span>
账号:<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"text"</span><span style="color: black;">/></span><span style="color: black;"><!--单行文本框--></span>
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--换行--></span>
<span style="color: black;">暗码</span>:<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"password"</span><span style="color: black;">/></span><span style="color: black;"><!--<span style="color: black;">暗码</span>文本框--></span>
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--换行--></span>
<span style="color: black;"><!--下面是单选按钮,有两个选项,二选一--></span>
性别:<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"radio"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"sex"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"male"</span><span style="color: black;">/></span>男
<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"radio"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"sex"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"female"</span><span style="color: black;">/></span>女
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--换行--></span>
<span style="color: black;"><!--下面是复选框,可多选--></span>
<span style="color: black;">兴趣</span>:<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"checkbox"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"interest"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"ah1"</span> <span style="color: black;">/></span>游泳
<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"checkbox"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"interest"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"ah2"</span> <span style="color: black;">/></span>篮球
<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"checkbox"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"interest"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"ah3"</span> <span style="color: black;">/></span>跑步
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--换行--></span>
简历:<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"file"</span> <span style="color: black;">/></span><span style="color: black;"><!--上传文件--></span>
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--换行--></span>
<span style="color: black;"><</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"submit"</span> <span style="color: black;">/></span><span style="color: black;"><!--提交按钮--></span>
<span style="color: black;"></</span><span style="color: black;">form</span><span style="color: black;">></span><span style="color: black;"><!--表单结束--></span>
<span style="color: black;"></</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">html</span><span style="color: black;">></span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:单选按钮【radio】和复选框【checkbox】里的【name】属性<span style="color: black;">必要</span>为同一值,<span style="color: black;">显示</span>这些选项归属于同一组。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/v2-0afdb3e25f635a100c1518d1008298d0_b.jpg" style="width: 50%; margin-bottom: 20px;"></div>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> <select> 元素(下拉元素):下拉列表能有效节约页面的<span style="color: black;">表示</span>空间,可在多个选项里<span style="color: black;">选择</span>其中一个。下拉列表由两个标签<span style="color: black;">构成</span>:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> <select>标签用于定义了一个下拉列表;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><option>标签定义了一个下拉列表里的选项;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">示例代码:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><!DOCTYPE html></span>
<span style="color: black;"><</span><span style="color: black;">html</span> <span style="color: black;">xmlns</span><span style="color: black;">=</span><span style="color: black;">"http://www.w3.org/1999/xhtml"</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">meta</span> <span style="color: black;">http-equiv</span><span style="color: black;">=</span><span style="color: black;">"Content-Type"</span> <span style="color: black;">content</span><span style="color: black;">=</span><span style="color: black;">"text/html; charset=utf-8"</span><span style="color: black;">/></span>
<span style="color: black;"><</span><span style="color: black;">title</span><span style="color: black;">></</span><span style="color: black;">title</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">form</span><span style="color: black;">></span>
请<span style="color: black;">选取</span>您的专业:
<span style="color: black;"><</span><span style="color: black;">select</span><span style="color: black;">></span><span style="color: black;"><!--定义一个下拉列表--></span>
<span style="color: black;"><</span><span style="color: black;">option</span><span style="color: black;">></span>计算机应用技术<span style="color: black;"></</span><span style="color: black;">option</span><span style="color: black;">></span><span style="color: black;"><!--列表选项--></span>
<span style="color: black;"><</span><span style="color: black;">option</span><span style="color: black;">></span>计算机软件与理论<span style="color: black;"></</span><span style="color: black;">option</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">option</span><span style="color: black;">></span>计算机体系结构<span style="color: black;"></</span><span style="color: black;">option</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">option</span><span style="color: black;">></span>软件工程<span style="color: black;"></</span><span style="color: black;">option</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">select</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">form</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">html</span><span style="color: black;">></span>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic4.zhimg.com/v2-dbb2c7a098e3568c5008115bb666ef2b_b.jpg" style="width: 50%; margin-bottom: 20px;"></div>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><textarea> 元素(多行文本):<span style="color: black;">咱们</span><span style="color: black;">能够</span>利用<textarea>元素创建一个文本块输入控件,用于输入多行文本,可输入的字数不受限制。<span style="color: black;">能够</span><span style="color: black;">经过</span>【rows】和【cols】属性来规定 textarea 的行数和列数(尺寸<span style="color: black;">体积</span>),<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">运用</span> CSS 的 height 和 width 属性。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 示例代码:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><!DOCTYPE html></span>
<span style="color: black;"><</span><span style="color: black;">html</span> <span style="color: black;">xmlns</span><span style="color: black;">=</span><span style="color: black;">"http://www.w3.org/1999/xhtml"</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">meta</span> <span style="color: black;">http-equiv</span><span style="color: black;">=</span><span style="color: black;">"Content-Type"</span> <span style="color: black;">content</span><span style="color: black;">=</span><span style="color: black;">"text/html; charset=utf-8"</span><span style="color: black;">/></span>
<span style="color: black;"><</span><span style="color: black;">title</span><span style="color: black;">></</span><span style="color: black;">title</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">style</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"text/css"</span><span style="color: black;">></span>
<span style="color: black;">#</span><span style="color: black;">textarea2</span>
<span style="color: black;">{</span><span style="color: black;">/*设置ID为textarea2的多行文本框的宽、高尺寸*/</span>
<span style="color: black;">width</span><span style="color: black;">:</span><span style="color: black;">200</span><span style="color: black;">px</span><span style="color: black;">;</span>
<span style="color: black;">height</span><span style="color: black;">:</span><span style="color: black;">80</span><span style="color: black;">px</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
<span style="color: black;"></</span><span style="color: black;">style</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">head</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">form</span><span style="color: black;">></span>个人简介:<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--该多行文本框的<span style="color: black;">体积</span>为5行30列--></span>
<span style="color: black;"><</span><span style="color: black;">textarea</span> <span style="color: black;">rows</span><span style="color: black;">=</span><span style="color: black;">"5"</span> <span style="color: black;">cols</span><span style="color: black;">=</span><span style="color: black;">"30"</span><span style="color: black;">></span>请介绍一下你自己<span style="color: black;"></</span><span style="color: black;">textarea</span><span style="color: black;">></span>
<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span>
学习心得:<span style="color: black;"><</span><span style="color: black;">br</span> <span style="color: black;">/></span><span style="color: black;"><!--用CSS设置该多行文本框的<span style="color: black;">体积</span>--></span>
<span style="color: black;"><</span><span style="color: black;">textarea</span> <span style="color: black;">id</span><span style="color: black;">=</span><span style="color: black;">"textarea2"</span><span style="color: black;">></span>学习心得(不少于400字)<span style="color: black;"></</span><span style="color: black;">textarea</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">form</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">body</span><span style="color: black;">></span>
<span style="color: black;"></</span><span style="color: black;">html</span><span style="color: black;">></span>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-8d688684ba2d88d710beec5c78512b86_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">小结一下</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">小结一下:表单元素的标签<span style="color: black;">咱们</span>初步记住三个<span style="color: black;">就可</span>:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、输入元素<input>:这个里面<span style="color: black;">包含</span>了<span style="color: black;">非常多</span><span style="color: black;">区别</span>类型的标签,<span style="color: black;">例如</span>:单行文本框、<span style="color: black;">暗码</span>框、按钮、单选按钮、多选框等等,它们用【type】属性加以区分。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、下拉列表< select >:<span style="color: black;">便是</span>个下拉列表框,<span style="color: black;">无</span>其它类别。由两部分<span style="color: black;">构成</span>:定义标签< select >和选项标签< option >,</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3、多行文本< textarea >:<span style="color: black;">便是</span>多行文本框,<span style="color: black;">亦</span><span style="color: black;">无</span>其它类别。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">其实<span style="color: black;">倘若</span><span style="color: black;">咱们</span>学习后台<span style="color: black;">研发</span>,<span style="color: black;">例如</span>利用微软的VS平台,在它的<span style="color: black;">工具</span>箱里有所有的标签控件,<span style="color: black;">咱们</span><span style="color: black;">能够</span>直接拉到编辑窗口直接<span style="color: black;">运用</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">-------------------------- END --------------------------</p>
论坛的成功是建立在我们诚恳、务实、高效、创新和团结合作基础上,我们要把这种精神传递下去。
页:
[1]