Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
334
12
minlength
maxlength
字符串输入框的最小长度和最大长度。
pattern
在输入框内输入的内容必须满足的正则表达式。
required
提交表单之前必须填写的输入框。
type
让开发人员指定输入框的内容类型,例如日期、电子邮件地址、数字、密码、
URL
,或者其他预设的特定类型。
另外,可以使用
CSS
选择符匹配
:valid
:invalid
入框。
因此,简单的表单可能完全不需要使用
JavaScript
。如果你想进一步控制表单验
证的外观和行为,最好使用
JavaScript
库,不要依赖
HTML5
CSS
表单验证规
范。如果你想为表单添加无障碍功能,笔者建议阅读
WebAIM
网站中的“
Creating
Accessible Forms
”一文(
https://oreil.ly/5oL3E
)。
12.17
突出显示表单错误并符合无障碍功能要
12.17.1
问题
你想突出显示数据有错误的表单字段,并确保突出效果对所有网页用户都行之有效。
12.17.2
方案
使用
CSS
突出显示输入错误的表单字段,并使用
WAI-ARIA
Web Accessibility
Initiative-Accessible Rich Internet Applications
)标记,确保突出效果对所有用户都
清晰明了。
处理
HTML
335
[
aria-invalid
] {
background-color
: #f5b2b2;
}
为需要验证的表单字段依附一个
oninput
事件处理函数,检查字段的值是否有效。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript

JavaScript

T. J. Crowder
JavaScript

JavaScript

David Flanagan
JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov

Publisher Resources

ISBN: 9787519869601