Sar*_*iji -1 javascript reactjs
我是 reactjs 的新手,我试图获取 textarea 字符数,需要在用户输入 textarea 时显示,但无法获取计数也抛出状态对象是只读错误。我的代码是
import React from "react";
export default function FullWidthTabs() {
const [textAreaCount = 0, textAreaTotal = 250] = React.useState(0);
const recalculate = e => {
console.log("event value:", e);
textAreaCount = e.target.value.length;
};
return (
<textarea
type="text"
rows={5}
className="full_height_Width"
onChange={recalculate}
/>
);
}
Run Code Online (Sandbox Code Playgroud)
import React from "react";
import "./styles.css";
export default function App() {
const [count, setCount] = React.useState(0);
return (
<div>
<textarea
type="text"
rows={5}
className="full_height_Width"
onChange={e => setCount(e.target.value.length)}
/>
<p>{count}</p>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2003 次 |
| 最近记录: |