Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
React快速上手开发
by
Stoyan Stefanov
March 2017
Intermediate to advanced
210 pages
5h 1m
Chinese
Posts & Telecom Press
Content preview from
React快速上手开发
JSX
|
79
4.13.2
value
和
defaultValue
的区别
在
HTML
中,如果你创建一个输入框
<input id="i" value="hello" />
,然后在输入框中
键入
bye
,你会发现:
i.value; // "bye"
i.getAttribute('value'); // "hello"
而在
React
中,
value
属性总是和文本输入框的最新内容保持一致。如果你想指定默认值,
可以使用
defaultValue
属性。
在下面这个代码片段中,你拥有一个
<input>
组件。该组件预先填充的内容为
hello
,还
绑定了一个
onChange
处理器。当把
hello
的最后一个字符
o
删掉时,
value
的值变为
hell
,
而
defaultValue
的值仍然是
hello
:
function log(event) {
console.log("value: ", event.target.value);
console.log("defaultValue: ", event.target.defaultValue);
}
React.render(
<input defaultValue="hello" onChange={log} />,
document.getElementById('app')
);
你应当把这种模式应用到自定义组件中:如果你需要接收一个属性,并暗示
用户该属性应该一直是最新的(比如
value
、
data
),就让其保持更新。否则
请把属性名改为
initialData ...
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.
Start your free trial
You might also like
JSON實務手冊
Tom Marrs
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
React学习手册
Alex Banks, Eve Porcello
数据压缩入门
Colt McAnlis, Aleks Haecky
Publisher Resources
ISBN: 9787115447739