【发布时间】:2021-07-20 04:57:14
【问题描述】:
我希望用户输入按钮的颜色并让它动态地更改为用户输入的任何颜色。 我还是新手,无法做出反应并试图弄清楚。
import React, { useState } from "react";
function App() {
const [name, setName] = useState("white");
function handleChange(event) {
console.log(event.target.value);
setName(event.target.value);
}
return (
<div className="container">
<h1>{name}</h1>
<input
onChange={handleChange}
type="text"
placeholder="What's your name?"
/>
<button type="text" style={{ backgroundColor: { name } }}>
Submit
</button>
</div>
);
}
export default App;
【问题讨论】:
标签: html css reactjs button background-color