<input> 属性HTML <input> 元素是表单中最常用的控件之一。通过设置不同的属性,可以控制 <input> 元素的行为、外观、验证规则等。以下是一些常见的 <input> 属性及其说明。
typetext、password、email、radio、checkbox 等。<input type="text" name="username" placeholder="请输入用户名"><input type="password" name="password" placeholder="请输入密码">php116 Bytes© 菜鸟-创作你的创作name<input type="text" name="username" placeholder="请输入用户名"><input type="password" name="password" placeholder="请输入密码">php116 Bytes© 菜鸟-创作你的创作valuevalue 指定初始显示内容。对于复选框和单选按钮,value 指定提交时提交的值。<input type="text" name="username" value="john_doe"><input type="submit" value="提交"><input type="radio" name="gender" value="male"> 男<input type="radio" name="gender" value="female"> 女php187 Bytes© 菜鸟-创作你的创作placeholder<input type="text" name="email" placeholder="请输入邮箱地址"><input type="password" name="password" placeholder="请输入密码">php114 Bytes© 菜鸟-创作你的创作id<label> 元素配合使用,增强可访问性。<label for="username">用户名:</label><input type="text" id="username" name="username">php84 Bytes© 菜鸟-创作你的创作class<input type="text" name="username" class="input-field">php55 Bytes© 菜鸟-创作你的创作required<input type="text" name="username" required placeholder="请输入用户名"><input type="email" name="email" required placeholder="请输入邮箱">php128 Bytes© 菜鸟-创作你的创作readonly<input type="text" name="username" value="john_doe" readonly>php61 Bytes© 菜鸟-创作你的创作disabled<input type="text" name="username" disabled placeholder="该字段已禁用">php65 Bytes© 菜鸟-创作你的创作maxlength<input type="text" name="username" maxlength="20" placeholder="最多输入20个字符">php74 Bytes© 菜鸟-创作你的创作minlength<input type="password" name="password" minlength="8" placeholder="密码至少8个字符">php76 Bytes© 菜鸟-创作你的创作min 和 max<input type="number" name="age" min="18" max="100" placeholder="请输入年龄"><input type="date" name="dob" min="1900-01-01" max="2025-12-31">php136 Bytes© 菜鸟-创作你的创作step<input type="number" name="quantity" min="1" max="10" step="1" value="1"><input type="time" name="meetingTime" step="900">php123 Bytes© 菜鸟-创作你的创作autofocus<input type="text" name="username" autofocus placeholder="请输入用户名">php66 Bytes© 菜鸟-创作你的创作autocompleteon 表示启用,off 表示禁用。<input type="email" name="email" autocomplete="on" placeholder="请输入邮箱">php71 Bytes© 菜鸟-创作你的创作accepttype="file"),指定用户可上传的文件类型。<input type="file" name="file" accept="image/*">php48 Bytes© 菜鸟-创作你的创作multiple<input type="file" name="files" multiple>php41 Bytes© 菜鸟-创作你的创作pattern<input type="text" name="zipcode" pattern="[0-9]{5}" placeholder="请输入邮政编码">php75 Bytes© 菜鸟-创作你的创作size<input type="text" name="username" size="20" placeholder="最多显示20个字符">php69 Bytes© 菜鸟-创作你的创作form<input> 控件与多个表单关联。<form id="form1" action="submit_form1.php"> <input type="text" name="username"></form><form id="form2" action="submit_form2.php"> <input type="text" name="username" form="form1"></form>php197 Bytes© 菜鸟-创作你的创作targettype="image" 的情况下,指定点击图像提交表单后的目标窗口。<input type="image" src="submit_button.png" alt="Submit" target="_blank">php73 Bytes© 菜鸟-创作你的创作type="image" 一起使用。通过使用不同的 <input> 属性,可以定制表单控件的行为和验证规则。合理利用这些属性,可以提高表单的用户体验、增强表单验证并确保数据的准确性。https://www.52runoob.com/archives/5085
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。