黑马程序员-html之表单组件<form>,下拉菜单<select>,文本域<textarea>

本文深入探讨了HTML表单标签的基本概念、常见标签类型及其应用场景,包括输入、选择、按钮等元素,同时强调了表单组件命名的重要性,并提供实例说明。


表单标签:

表单标签是最常用的标签,用于与服务器端的交互。

<input>:输入标签,接收用户的输入信息,其中的type属性指定输入标签的类型,必须知道的有10

1、文本框 text:输入的文本信息直接显示在框中

2、密码框 password:输入的文本信息以原点或星号的形式显示

3、单选框 radio:例如:性别选择框

4、复选框 checkbox  例如:兴趣选择

5、隐藏字段 hidden :在页面中不显示,但在提交的时候,随其他内容一起提交

6、选择文件 file

7、图片 image:具备提交效果,功能是提交数据

8、按钮 button :为按钮添加事件,用onClick属性

9、reset   :清空按钮

10、submit :提交按钮

注意:1、单选框,在使用时必须将所有的单选选项指定到一个组了,否则实现不了单选效果,eg:性别选择 <input type=radio name=sex>

                 <input type=radio name=sex>

2、<input type=reset value=清除数据/>

   <input type=submit value=提交数据  checked=checked>

 

 

3、特别注意:表单的组件必须指定name value属性。Eg

<input type=text name=user value=””>

为什么要这么做呢?Value对于需要输入内容再提交(用户名,密码)无用,但是也必须写,value=””,像其他组件单选,复选就用到了,<input type=radio name=sex value=nan>

否则服务器都不知道提交的是什么内容。

4、<input type=button value=按钮 onClick=alert(一个按钮)/>

 

 

下拉菜单<select>

<select name="country">

<option value="none">选择国家</option>

<option value="usa">英国</option>

<option value="ca" selected="selected">中国</option>

</select>

注意也必须有name value属性

 

 

文本域:<textarea>

<textarea  name=text> </textarea>

注意  <select>与<textarea>也是<form>标签的内容




<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>大学生暑期社会实践报名表</title> </head> <body> <!-- 页面主标题 --> <h1 align="center">大学生暑期社会实践报名表</h1> <hr> <!-- 表单开始区域 --> <form action="#" method="POST"> <!-- 1. 文本输入框 --> <label for="stuName">学生姓名:</label> <input type="text" id="stuName" name="username" placeholder="请输入真实姓名"> <br><br> <!-- 2. 密码框(演示用,如查询密码) --> <label for="pwd">查询密码:</label> <input type="password" id="pwd" name="password" placeholder="设置6位查询密码"> <br><br> <!-- 3. 单选按钮 (注意 name 必须相同才能互斥) --> <label>您的性别:</label> <input type="radio" id="male" name="gender" value="男" checked> <label for="male">男</label> <input type="radio" id="female" name="gender" value="女"> <label for="female">女</label> <br><br> <!-- 4. 下拉菜单 --> <label for="campus">所在校区:</label> <select id="campus" name="campus"> <option value="">--请选择--</option> <option value="north">北校区</option> <option value="south">南校区</option> <option value="east">东校区</option> </select> <br><br> <!-- 5. 复选框 (可多选) --> <label>意向岗位(多选):</label> <br> <input type="checkbox" id="teach" name="job" value="支教"> <label for="teach">乡村支教</label> <br> <input type="checkbox" id="research" name="job" value="调研"> <label for="research">社会调研</label> <br> <input type="checkbox" id="tech" name="job" value="技术"> <label for="tech">技术支持</label> <br><br> <!-- 6. 日期选择器 --> <label for="birthday">出生日期:</label> <input type="date" id="birthday" name="birthday"> <br><br> <!-- 7. 文件上传 --> <label for="resume">上传简历:</label> <input type="file" id="resume" name="file"> <br><br> <!-- 8. 多行文本域 --> <label for="intro">个人优势/备注:</label><br> <textarea id="intro" name="intro" rows="5" cols="40" placeholder="请简述你的特长..."></textarea> <br><br> <!-- 9. 按钮区域 --> <input type="submit" value="立即报名">    <input type="reset" value="重新填写"> </form> <br> <hr> <p align="center"><small>版权所有 © 2025 学生工作处</small></p > </body> </html>以上哪里有问题帮我修改并输出正确的
最新发布
12-09
<div v-for="(process, index) in form.processes" :key="index" class="table-row"> <!-- 名称 --> <div class="col"> <el-form-item :prop="`processes.${index}.processName`" :rules="rules.processName"> <el-input v-model="form.processes.processName" placeholder="工序名称" /> </el-form-item> </div> <!-- 英语名称 --> <div class="col"> <el-form-item :prop="`processes.${index}.englishName`" :rules="rules.englishName"> <el-input v-model="process.englishName" placeholder="English Name" /> </el-form-item> </div> <!-- 流程卡内容 --> <div class="col"> <el-form-item> <el-input v-model="process.cardContent" type="textarea" :autosize="{ minRows: 1, maxRows: 3}" class="scrollable-textarea" /> </el-form-item> </div> <!-- 时间参数组 --> <div class="col"> <el-form-item> <el-input v-model="process.processWatitime" /> </el-form-item> </div> <!-- 运行(H) --> <div class="col"> <el-form-item> <el-input v-model="process.machineRuntime" /> </el-form-item> </div> <!-- set_up --> <div class="col"> <el-form-item> <el-input v-model="process.setuptime" placeholder="min/pcs" /> </el-form-item> </div> <!-- 人工 --> <div class="col"> <el-form-item> <el-input v-model="process.labortime" placeholder="min/pcs" /> </el-form-item> </div> <!-- 单位 --> <div class="col"> <el-form-item> <el-input v-model="process.routerUnit" /> </el-form-item> </div> <!-- 数量 --> <div class="col"> <el-form-item> <el-input v-model="process.quantity" /> </el-form-item> </div> <!-- 状况 --> <div class="col"> <el-form-item> <el-select v-model="process.routerStatus" placeholder="状态"> <el-option v-for="dict in dict.type.router_status" :key="dict.value" :label="dict.label" :value="dict.value" /> </el-select> </el-form-item> </div> <!-- 代码 --> <div class="col"> <el-form-item> <el-input v-model="process.processCode" /> </el-form-item> </div> <!-- 操作 --> <div class="col"> <el-button type="danger" icon="el-icon-delete" circle @click="removeProcess(index)" /> </div> </div>测试生成十条数据
09-28
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML表单实验 - 学生信息采集</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif; } body { background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c); background-size: 400% 400%; animation: gradientBG 15s ease infinite; color: #333; min-height: 100vh; padding: 20px; display: flex; justify-content: center; align-items: center; } @keyframes gradientBG { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } .container { max-width: 1000px; width: 100%; margin: 0 auto; } header { text-align: center; margin-bottom: 30px; padding: 20px; background: rgba(255, 255, 255, 0.9); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); } h1 { color: #1a2a6c; font-size: 2.5rem; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); } .subtitle { color: #b21f1f; font-size: 1.2rem; margin-bottom: 15px; } .experiment-info { display: flex; justify-content: center; gap: 30px; margin-top: 15px; flex-wrap: wrap; } .info-card { background: linear-gradient(135deg, #1a2a6c, #3a7bd5); color: white; padding: 15px 25px; border-radius: 8px; text-align: center; min-width: 200px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); } .info-card h3 { margin-bottom: 8px; font-size: 1.2rem; } .form-container { background: rgba(255, 255, 255, 0.95); border-radius: 15px; padding: 30px; box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3); } h2 { text-align: center; color: #1a2a6c; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 2px solid #b21f1f; } table { width: 100%; border-collapse: collapse; margin-bottom: 25px; } th { background: #1a2a6c; color: white; padding: 12px; text-align: left; width: 30%; } td { padding: 12px; background: rgba(240, 240, 245, 0.7); } tr:nth-child(even) td { background: rgba(230, 230, 240, 0.7); } input, select, textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; transition: all 0.3s; } input:focus, select:focus, textarea:focus { outline: none; border-color: #3a7bd5; box-shadow: 0 0 8px rgba(58, 123, 213, 0.5); } .radio-group, .checkbox-group { display: flex; gap: 20px; flex-wrap: wrap; } .radio-option, .checkbox-option { display: flex; align-items: center; gap: 6px; } .form-buttons { display: flex; justify-content: center; gap: 20px; margin-top: 20px; } button { padding: 14px 35px; border: none; border-radius: 50px; font-size: 18px; font-weight: bold; cursor: pointer; transition: all 0.3s; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); } .submit-btn { background: linear-gradient(to right, #1a2a6c, #3a7bd5); color: white; } .reset-btn { background: linear-gradient(to right, #b21f1f, #e74c3c); color: white; } button:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); } button:active { transform: translateY(1px); } .requirements { background: rgba(26, 42, 108, 0.1); padding: 20px; border-radius: 10px; margin-top: 30px; } .requirements h3 { color: #1a2a6c; margin-bottom: 15px; text-align: center; } .requirements-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; } .requirement-item { background: rgba(255, 255, 255, 0.8); padding: 15px; border-radius: 8px; display: flex; align-items: center; gap: 10px; } .requirement-item i { background: #1a2a6c; color: white; width: 30px; height: 30px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-weight: bold; } footer { text-align: center; margin-top: 30px; color: rgba(255, 255, 255, 0.9); font-size: 0.9rem; } @media (max-width: 768px) { th, td { display: block; width: 100%; } th { margin-top: 15px; border-radius: 6px 6px 0 0; } .form-buttons { flex-direction: column; } } </style> </head> <body> <div class="container"> <header> <h1>HTML 语言实验</h1> <p class="subtitle">表单设计与实现 - 学生信息采集系统</p> <div class="experiment-info"> <div class="info-card"> <h3>实验目的</h3> <p>掌握利用HTML语言编写表单的能力</p> </div> <div class="info-card"> <h3>实验课时</h3> <p>2 学时</p> </div> <div class="info-card"> <h3>实验要求</h3> <p>表格布局 · 6个以上元素 · 5种表单控件</p> </div> </div> </header> <div class="form-container"> <h2>学生基本信息登记表</h2> <form action="#" method="post"> <table> <tr> <th><label for="name">姓名</label></th> <td><input type="text" id="name" name="name" required placeholder="请输入您的姓名"></td> </tr> <tr> <th><label for="student-id">学号</label></th> <td><input type="text" id="student-id" name="student_id" required placeholder="请输入您的学号"></td> </tr> <tr> <th><label for="email">电子邮箱</label></th> <td><input type="email" id="email" name="email" required placeholder="example@university.edu.cn"></td> </tr> <tr> <th><label for="password">密码</label></th> <td><input type="password" id="password" name="password" required placeholder="设置登录密码"></td> </tr> <tr> <th><label>性别</label></th> <td> <div class="radio-group"> <div class="radio-option"> <input type="radio" id="male" name="gender" value="male"> <label for="male">男</label> </div> <div class="radio-option"> <input type="radio" id="female" name="gender" value="female"> <label for="female">女</label> </div> <div class="radio-option"> <input type="radio" id="other" name="gender" value="other"> <label for="other">其他</label> </div> </div> </td> </tr> <tr> <th><label for="birthdate">出生日期</label></th> <td><input type="date" id="birthdate" name="birthdate"></td> </tr> <tr> <th><label for="college">所属学院</label></th> <td> <select id="college" name="college"> <option value="">-- 请选择学院 --</option> <option value="computer">计算机科学与技术学院</option> <option value="electronic">电子信息工程学院</option> <option value="mechanical">机械工程学院</option> <option value="business">商学院</option> <option value="art">艺术学院</option> <option value="science">理学院</option> </select> </td> </tr> <tr> <th><label>兴趣爱好</label></th> <td> <div class="checkbox-group"> <div class="checkbox-option"> <input type="checkbox" id="sports" name="interests" value="sports"> <label for="sports">体育运动</label> </div> <div class="checkbox-option"> <input type="checkbox" id="music" name="interests" value="music"> <label for="music">音乐</label> </div> <div class="checkbox-option"> <input type="checkbox" id="reading" name="interests" value="reading"> <label for="reading">阅读</label> </div> <div class="checkbox-option"> <input type="checkbox" id="travel" name="interests" value="travel"> <label for="travel">旅行</label> </div> </div> </td> </tr> <tr> <th><label for="bio">个人简介</label></th> <td> <textarea id="bio" name="bio" rows="4" placeholder="请简要介绍你自己..."></textarea> </td> </tr> <tr> <th><label>照片上传</label></th> <td><input type="file" id="photo" name="photo" accept="image/*"></td> </tr> </table> <div class="form-buttons"> <button type="submit" class="submit-btn">提交信息</button> <button type="reset" class="reset-btn">重置表单</button> </div> </form> <div class="requirements"> <h3>实验要求实现情况</h3> <div class="requirements-list"> <div class="requirement-item"> <i>1</i> <div>使用表格进行表单布局 - <strong>已实现</strong></div> </div> <div class="requirement-item"> <i>2</i> <div>包含6个以上表单元素 - <strong>已实现(11个元素)</strong></div> </div> <div class="requirement-item"> <i>3</i> <div>使用5种以上表单控件 - <strong>已实现(7种控件)</strong></div> </div> <div class="requirement-item"> <i>4</i> <div>表单控件类型:文本输入、密码、单选、复选、下拉选择、文本域、文件上传、日期选择器</div> </div> </div> </div> </div> <footer> <p>HTML 语言实验报告 | 网页设计与开发 | © 2023 计算机科学与技术学院</p> </footer> </div> </body> </html>
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值