表单主要用来收集客户端提供的相关信息,使网页具有交互的功能,它是用户与网页实现交互的重要手段。
表单是网页上的一个特定区域,这个区域通过
输入标签是标签,通过设置其"type"的属性值改变其输入方式,而不同的输入方式又会导致其他参数因此而异。
表单中的文本框主要有两种,分别是单行文本框和密码输入框。不同的文本框对应的"type"属性值也不同,其对应的表现形式和应用也各有差异。 使用标签绑定单行文本框,实现单击图片时文本框也能获取焦点
text属性用来设定在表单的文本框中输入任何类型的文本、数字或字母。输入的内容以单行显示。 其语法格式如下:
在HTML中, 元素用于定义表单控件的标签。for属性是元素的一个属性,它的作用是指定与该标签关联的表单控件的ID。 通过将的for属性设置为相关表单控件的ID,用户就可以点击的文本部分时,自动触发关联表单控件的功能。这提高了用户体验,尤其是在大型表单中。
在这个例子中,for属性的值是 “name”,它与元素的id属性值相对应。这意味着当用户点击"用户名:"这个标签时,浏览器会自动将焦点设置到ID为"name"的输入框上,方便用户进行输入。如果没有使用for属性,这种关联行为可能就不会发生。
输入文本域中的文字均以星号"*"或圆点显示 其语法格式如下:
使用标签绑定单选框/复选框,当单击按钮旁边的汉字时,也能选中对应按钮
提交按钮 提交按钮是一种特殊的按钮,不需要设置onclick属性,在单击该类按钮时可以实现表单内容的提交 其语法格式如下: 当提交按钮没有设置按钮取值时,其默认取值为"提交"。也就是在提交按钮上默认显示的文字为"提交"
重置按钮 单击重置按钮后,可以清楚表单的内容,恢复默认的表单内容设定。 其语法格式如下: 当重置按钮没有设置按钮取值时,在该按钮上默认显示的文字为"重置" 也可使用button元素来表示一个可点击的按钮
文本域和文本框的区别在于,文本域可以显示多行文字;而菜单/列表与单选按钮或复选框相比,既可以有多个选择项,又不浪费空间,还可以减少代码量
它与文本框的区别在于可以添加多行文字,从而可以输入更多的文本 其语法格式如下:
css属性resize:
菜单列表类的控件主要用来选择给定答案中的一种,这类选择往往答案比较多,使用单选按钮比较浪费空间。可以说,菜单列表类的控件主要是为了节省页面空间而设计的。菜单和列表都是通过和标签来实现的。 菜单是一种最节省空间的方式,正常状态下只能看到一个选项,单击按钮打开菜单后才能看到全部选项 列表可以显示一定数量的选项,如果超出了这个数量,则会自动出现滚动条,浏览者可以通过拖动滚动条显示各选项
optgroup:为元素中的选项创建分组
DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../reset.css"> <title>Documenttitle> <style> .container { width: 190px; height: 65px; background-color: #fff; box-shadow: inset 0 0 5px 1px #ccc; margin: 2px auto; } p { color: #666; font: 14px Segoe Print; font-weight: bold; text-align: center; background-color: lightblue; } div.option { width: 80px; height: 20px; border: 2px solid #ccc; border-radius: 5px; position: absolute; } div.part-two { position: relative; height: 30px; } div.numOne { left: 5px; top: 5px; } div.numTwo { right: 5px; top: 5px; } label span.text { font: 12px Segoe Print; color: #999; } .part-two .option label span.newstyle { width: 13px; height: 13px; border: 1.5px solid #ccc; border-radius: 50%; box-sizing: border-box; display: inline-block; position: relative; left: 3px; top: 1.5px; } .part-two .option label:hover span[class="newstyle"] { border: 1.5px solid #999; } input[type="radio"]:checked+span[class="newstyle"] { border: 2px solid #999; background-color: #ccc; } input[type="radio"] { display: none; } style> head> <body> <div class="container"> <div class="part-one"> <p>Choose Your Optionp> div> <div class="part-two"> <div class="option numOne"> <label for="numOne"> <input id="numOne" name="choose" type="radio"> <span class="newstyle">span> <span class="text">OPTION1span> label> div> <div class="option numTwo"> <label for="numTwo"> <input id="numTwo" name="choose" type="radio"> <span class="newstyle">span> <span class="text">OPTION2span> label> div> div> div> body> html>
京公网安备 11010502049817号